Greatym.com Greatym.com - 4 months ago 10
jQuery Question

Angular js : Unable to create directive

I am trying to create directive but my directive function is not getting called.

index.html

<div ng-repeat="que in questions.Cars">
<question-dir>print from direcetive</question-dir>
</div>


ConytrolDirective.js

(function () {
"use strict";

angular
.module("autoQuote")
.directive('questionDir',["questionDir"] );

function questionDir()
{
return {
template : "<h1>Made by a directive!</h1>"
};
}

}());


Below is the plunker for code
http://plnkr.co/edit/Op1QDwUBECAosPUC7r3N?p=preview

Answer

There have several mistakes

  1. You should have function name instead of "questionDir"
    .directive('questionDir',[questionDir] );

  2. Use kebab case(- separated words) while using directive name

    `<question-dir>print from direcetive</question-dir>`
    
  3. Additionally you need to refer <script src="controlDirectives.js"></script> on your index.html page.

Demo here