请看这个Plunker
我有一个使用自定义角度指令的HTML
<body ng-controller="myCtrl">
<h1>Hello Plunker!</h1>
<div><sample attributeone="Sample Attribute"></sample></div>
</body>
Run Code Online (Sandbox Code Playgroud)
我的指令看起来像这样:
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;
}
};
}
};
});
Run Code Online (Sandbox Code Playgroud)
在我看来,对pre中compile应该执行bofore模板返回,并value应设置为"Sample Attribute".但它没有得到评估.
预期产出 …