Created
August 7, 2015 08:25
-
-
Save ikbear/14aa1a2ba839d1585d4d to your computer and use it in GitHub Desktop.
Angularjs - how do i access directive attribute in controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// URL: http://stackoverflow.com/questions/24864956/angularjs-how-do-i-access-directive-attribute-in-controller | |
app.directive('rating', [function () { | |
return { | |
restrict: 'E', | |
scope: { | |
maxStars: '=', | |
url: '@' | |
}, | |
controller: 'ratingController' | |
}; | |
}); | |
// Meanwhile, in some other file | |
app.controller('ratingController', function ($scope, $element, $attrs) { | |
// Access $attrs.url | |
// Better yet, since you have put those values on the scope, | |
// access them like this: $scope.url | |
... | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment