1

I am new to AngularJs. I am trying to invoke custom directive but it is not getting invoked.

<head>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
    <script src="customDirective.js"></script>
</head>
<body>
    <div ng-app="app">
        <div ng-controller="MyController as ctrl">
            <testingDirective></testingDirective>
            {{ctrl.test}}
        </div>

    </div>

</body>

My javascript file looks like:

var app=angular.module('app',[]);
app.controller('MyController',[function(){
    var self=this;
    self.test='no';
    
    }]);
app.directive('testingDirective',function(){
    return{
            
            restrict:'AE',
            replace:true,
            template:'<h1>Hello World Test</h1>'
        };
    });

2 Answers 2

5

Camel cased directive names have to be called using a hyphen. For example, if you have a directive named myDirective, you would use it in the markup as <my-directive></my-directive>.

Sign up to request clarification or add additional context in comments.

Comments

5

Directive:

app.directive('testingDirective',function(){});

HTML Usage:

<testing-directive></testing-directive>

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.