user2167582 user2167582 - 1 year ago 98
AngularJS Question

how to obtain $attr manually in angular

I want to know how I might manually obtain the attribute from the linkFn call back.

e.g. if I want scope, I do,




how about for attr.

Answer Source

In the parent controller I suppose you could access the attributes object after first assigning it to a scope property in the directive:

<div ng-controller="MyCtrl">
    <div my-directive attr1="one">see console log</div>
app.directive('myDirective', function() {
    return {
        link: function(scope, element, attrs) {
            scope.attrs = attrs

function MyCtrl($scope, $timeout) {
    $timeout(function() {
    }, 1000);


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download