请看这
Plunker
我有一个使用自定义角度指令的HTML
- <body ng-controller="myCtrl">
- <h1>Hello Plunker!</h1>
- <div><sample attributeone="Sample Attribute"></sample></div>
- </body>
我的指令看起来像这样:
- myApp.directive('sample',function() {
- var value = "";
- return {
- replace: true,restrict: 'E',scope : false,template: '<div>This is a sample Paragraph '+ value + '</div>',compile: function ( tElement,tAttributes ) {
- return {
- pre: function preLink( scope,element,attributes ) {
- console.log( attributes.log + ' (pre-link)' );
- value = tAttributes.attributeone;
- }
- };
- }
- };
- });
在我看来,编译前应该执行bofore返回模板,值应该设置为“Sample Attribute”.但它没有得到评估.
预期产出
- This is a sample Paragraph Sample Attribute
实际产出
- This is a sample Paragraph
有没有其他方法可以在模板中设置值?