Please help me, how can we get AngularJS to compile the code generated by the directive?
You can even find the same code here, http://jsbin.com/obuqip/4/edit
HTML
<div ng-controller="myController"> {{names[0]}} {{names[1]}} <br/> <hello-world my-username="names[0]"></hello-world> <br/> <hello-world my-username="names[1]"></hello-world> <br/><button ng-click="clicked()">Click Me</button> </div>
Javascript
var components= angular.module('components', []); components.controller("myController", function ($scope) { var counter = 1; $scope.names = ["Number0","lorem","Epsum"]; $scope.clicked = function() { $scope.names[0] = "Number" + counter++; }; } ); // **Here is the directive code** components.directive('helloWorld', function() { var directiveObj = { link:function(scope, element, attrs) { var strTemplate, strUserT = attrs.myUsername || ""; console.log(strUserT); if(strUserT) { strTemplate = "<DIV> Hello" + "{{" + strUserT +"}} </DIV>" ; } else { strTemplate = "<DIV>Sorry, No user to greet!</DIV>" ; } element.replaceWith(strTemplate); }, restrict: 'E' }; return directiveObj; });
angularjs
Sunnyshah
source share