- 11 months ago 34
jQuery Question

Angular js : Unable to create directive

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


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


(function () {
"use strict";

.directive('questionDir',["questionDir"] );

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


Below is the plunker for code


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