Curious "compile" function in angularjs directive -



Curious "compile" function in angularjs directive -

the total code in here of plunker

when remove compile: function (telement, tattrs, transclude) function, functionality ok

app.directive('whatisinthese', ['$compile', function($compile) { homecoming { restrict: 'a', compile: function (telement, tattrs, transclude) { // compile function curious , hard explain // have nil here }, link: function(scope, elem, attrs) { scope.gettesturl = function() { homecoming "test.html"; }; var these = attrs.whatisinthese.split(' '); var html = '<div ng-include src="gettesturl()"></div>'; var el = angular.element(html); var compiled = $compile(el); elem.append(el); compiled(scope); } }; }]);

can explain why happen?

as mentioned in documentation of angularjs

the compile function deals transforming template dom.[...] link property used if compile property not defined.

so this:

link: function (scope, elem, attrs) { scope.gettesturl = function () { homecoming "test.html"; }; var these = attrs.whatisinthese.split(' '); var html = '<div ng-include src="gettesturl()"></div>'; var el = angular.element(html); var compiled = $compile(el); elem.append(el); compiled(scope); }

is same as

compile: function (telement, tattrs, transclude) { homecoming function (scope, elem, attrs) { scope.gettesturl = function () { homecoming "test.html"; }; var these = attrs.whatisinthese.split(' '); var html = '<div ng-include src="gettesturl()"></div>'; var el = angular.element(html); var compiled = $compile(el); elem.append(el); compiled(scope); } };

angularjs angularjs-directive directive

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -