angularjs - Angular directive: compile is invoked, but not link -
i have following directive:
angular.module('mymodule', []).directive('mydir', function () { return { scope: {}, restrict: 'e', link: function () { alert('hello!'); } }; });
and i'm using in template so:
<my-dir attr1="hello" attr2="world" />
when load page, don't alert. however, if assign compile
property instead of link
property, alert. why not invoking link
function, it's happily invoking compile
?
note: tried return pre
/post
link object compile
function, yet still doesn't invoke anything. doesn't matter if make <my-dir>
self-closing (as above) or not.
same code working me check this
<html> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0-rc.0/angular.min.js"></script> <script type="text/javascript"> var myapp = angular.module('myapp',[]).directive('mydir', function () { return { scope: {}, restrict: 'e', link: function () { alert('hello!'); } }; }); </script> <body ng-app="myapp"> <my-dir attr1="hello" attr2="world" /> </body>
Comments
Post a Comment