2
傳遞多個值的指令與NG-重複我有一個自定義指令是這樣的:內
<user-preview closable="true" user="user" ng-repeat="user in users"></user-preview>
正如你所看到的,我通過兩個屬性給它:closable
和user
。用戶一切都很好,它會到達指令的內部模板。但可關閉不。它存在於內部範圍內,但在模板中由於某種原因,它的格式爲undefined
。 如果我提出NG-重複到一個外部變量,它的工作原理:
<span ng-repeat="user in users"><user-preview closable="true" user="user"></user-preview></span>
那麼,如何通過這兩個值與ng-repeat
裏面?可能嗎?
這裏是我的指令代碼,以防萬一:
.directive('userPreview', function() {
return {
scope: {
'user': '=',
'closable': '='
},
restriction: 'E',
replace: true,
priority: 1001,
templateUrl: '/static/angular_tpls/user_preview.html',
controller: function($scope) {
},
link: function(scope, element, attrs, ctrl) {
}
}
});
<span class="badge active user">
<a href="#">
<img ng-src="{{user.avatar}}" height="25px" class="img-circle">
</a>
<a href="#">
{{user.name}}
</a>
<span ng-if="closable" class="glyphicon glyphicon-remove-circle" ng-click="close()"></span>
</span>
http://stackoverflow.com/questions/15344306/ng-repeat-in-combination-with-custom-directive –
我已經使用了更高的優先級。 – troorl
請參閱:http://jsfiddle.net/sherali/GDfxd/213/。我有這樣的問題,但現在... –