0

I'm trying to create a directive in angularJS. But it's not working. What I have done is as follow.

my main html code

<body ng-app="birthdayToDo" ng-controller="main">
    <h1>Hello Plunker!</h1>
    <myCustomer></myCustomer>
  </body>

My Js code :

var app = angular.module('birthdayToDo', []);

app.controller('main', function($scope) {
  $scope.employees=[
                    {
                      Name:"Amit",
                      Email:"[email protected]"
                    },
                    {
                      Name:"Ajay",
                      Email:"[email protected]"
                    },
                    {
                      Name:"Rahul",
                      Email:"[email protected]"
                    },
                    {
                      Name:"Aakash",
                      Email:"[email protected]"
                    },
                    {
                      Name:"Rohit",
                      Email:"[email protected]"
                    },
                  ];

});
app.directive('myCustomer', function() {
    var directive = {};

    directive.restrict = 'E'; /* restrict this directive to elements */
    directive.templateUrl = "directiveFile.html";

    return directive;
  });

my directiveFile.html code

<table>
  <tr>
    <td>SNo.</td>
    <td>Name</td>
    <td>Email</td>
  </tr>
  <tr ng-repeat="employee in employees">
    <td>{{$index+1}}</td>
    <td>{{employee.Name}}</td>
    <td>{{employee.Email}}</td>
  </tr>
</table>

But this code is not working . What's wrong I'm doing.

Plunker link

3 Answers 3

2

You have 2 option of naming:

1.

app.directive('myCustomer', function()
<my-customer> </my-customer> 

2.

app.directive('mycustomer', function()
<mycustomer>  </mycustomer> 
Sign up to request clarification or add additional context in comments.

Comments

2

Change

<myCustomer></myCustomer>

To this:

<my-customer></my-customer>

Comments

2

Directives uses snake case.

change your HTML to this

<my-customer></my-customer>

Always remember ng-app, ng-click, etc

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.