Reputation: 4260
I have a directive that looks like this:
<div class="slidesShow" interval="5" ng-controller="slideshowController" ng-init="init()">
<img ng-repeat='item in slides' src="{{item.src}}" alt="{{item.alt}}" />
</div>
Can I get the value of the interval attribute in my controller function?
I have tried this:
angular.module('awsApp').controller('slideshowController', function ($scope, $http) {
$scope.init = function () {
console.log('unterval:' + $scope.attr.interval);
};
});
This gives ne the error: Error: $scope.attr is undefined
Can I acces this attribute? And if so, How?
Upvotes: 0
Views: 53
Reputation: 388446
You can inject attrs into the controller like
angular.module('my-app').controller('slideshowController', function ($scope, $http, $attrs) {
console.log($attrs)
$scope.init = function () {
console.log('unterval:' + $attrs.interval);
};
});
Demo: Fiddle
Upvotes: 2