[英]Angular, read attribute from directive tag
我有一個看起來像這樣的指令:
<div class="slidesShow" interval="5" ng-controller="slideshowController" ng-init="init()">
<img ng-repeat='item in slides' src="{{item.src}}" alt="{{item.alt}}" />
</div>
我可以在控制器函數中獲取interval屬性的值嗎?
我試過這個:
angular.module('awsApp').controller('slideshowController', function ($scope, $http) {
$scope.init = function () {
console.log('unterval:' + $scope.attr.interval);
};
});
這給出了錯誤:錯誤:$ scope.attr未定義
我可以訪問此屬性嗎? 如果是這樣,怎么樣?
您可以將attrs注入控制器
angular.module('my-app').controller('slideshowController', function ($scope, $http, $attrs) {
console.log($attrs)
$scope.init = function () {
console.log('unterval:' + $attrs.interval);
};
});
演示: 小提琴
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.