Skip to content

Instantly share code, notes, and snippets.

@ikbear
Created August 7, 2015 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikbear/14aa1a2ba839d1585d4d to your computer and use it in GitHub Desktop.
Save ikbear/14aa1a2ba839d1585d4d to your computer and use it in GitHub Desktop.
Angularjs - how do i access directive attribute in controller
// 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