angularjs代码:
app.directive('test', function(){
return {
restrict: 'A',
scope: {
myId: '@'
},
link: function(scope) {
alert(scope.myId);
}
}
});
你可以看到有一个 scope: { myId: '@' }
在指令中。
和HTML代码:
<div test my-id='123'></div>
你可以看到我定义了一个 my-id='123'
。
我希望该指令能够提醒 123
,但它提醒了 undefined
。我的错误在哪里?
PS:这是一个现场演示: http://plnkr.co/edit/sL69NqWC70Qfwav5feP2?p=preview