Book Image

Data Oriented Development with Angularjs

Book Image

Data Oriented Development with Angularjs

Overview of this book

Table of Contents (17 chapters)
Data-oriented Development with AngularJS
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Writing directives


Now that we've talked a lot about theory, let's put it into practice and write some directives. We'll start with very simple examples and go on to build complex ones, highlighting various aspects involved in writing directives. We'll keep using employee-related data which we've used in earlier examples to keep things simple, so here's our first simple directive.

Custom attributes

This directive uses an inline template and inherits the scope from the controller. This is not a good practice and is for illustration purposes only (as this is our very first directive). Here's the controller:

app.controller('EmployeeCtrl', ['$scope',
  function ($scope) {

    var Employee = function (name, age) {
      this.name = name;
      this.age = age;
    };

    var GetEmployees = function () {
      return [
        new Employee("First employee", 56),
        new Employee("Second employee", 44),
        new Employee("Last employee", 32)
      ];
    };

    $scope.employeeData = {
  ...