javascript - Angularjs - $compile element on click variable is not compiled -


i compile element oc click new variable after first click variable shows in curly brackets {{variable}} -> see plnkr

var app = angular.module("myapp",[]); app.directive('tester',function($compile){   return{     restrict:'e',     templateurl:'fruits.html',     replace:true,     link: function(scope,elem,attrs){       elem.bind("click", function(e){         scope.fruit = 'apple';          var template = "<p>{{fruit}}</p>";           elem.append(template);           $compile(elem.contents())(scope);       });      }   } }); 

all need is:

 elem.append(template);  $compile(elem.contents())(scope); 

as of compiling first , appending. swap lines , it'll work.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -