Passing attribute value to directive controller

Shreyas

Directive usage

<my-directive my-attr='StackOverflow'></my-directive>

Directive definiton

app.directive('myDirective', function($scope){
  return {
    restrict: 'E',
    template: 'I want to print the attribute value',
    controller: function($scope){
      // I also want to access the attribute value here.
    }
  };
});

Is there a way to achieve this.

Shreyas

Instead of scope: true write,

scope: {
  myattr: '@'
}

Then myattr will be available in $scope

Fiddle

Make sure to use small casing, somehow using any other casing like pascal or camel causes problems.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Passing Attribute Value to Directive Template

From Dev

AngularJS : Passing attribute value from one directive to transcluded one

From Dev

Accessing directive attribute in controller

From Dev

Set attribute value of angular directive from another controller

From Dev

Access attribute value inside non-directive controller function

From Dev

Getting an attribute value from a directive's isolated controller

From Dev

Set string as directive attribute value that maps to a member on the controller scope

From Dev

Passing a variable as ngModel to attribute directive

From Dev

Passing Boolean Value Into Directive

From Dev

AngularJs passing a value to a directive

From Dev

AngularJs passing a value to a directive

From Dev

Value not passing to directive - AngularJS

From Dev

AngularJS value not passing to directive

From Dev

Passing values from directive to controller

From Dev

passing values to controller from directive

From Dev

get directive attribute defined in HTML in directive controller

From Dev

Pass directive attribute into linked controller?

From Dev

Pass directive attribute into linked controller?

From Dev

Angular attribute directive value

From Dev

Passing a function as an attribute value

From Dev

AngularJS: passing boolean value to directive

From Dev

datetimepicker not passing value to Controller

From Dev

View Controller value passing

From Dev

Passing literal attribute values to angular js directive

From Dev

Problems with passing callback from controller to directive

From Dev

AngularJS controller variable not passing to child directive

From Dev

Passing data from directive to parent scope controller

From Dev

Angular Directive bind function with & not passing arguments to controller

From Dev

Passing variable from controller scope to directive

Related Related

  1. 1

    Passing Attribute Value to Directive Template

  2. 2

    AngularJS : Passing attribute value from one directive to transcluded one

  3. 3

    Accessing directive attribute in controller

  4. 4

    Set attribute value of angular directive from another controller

  5. 5

    Access attribute value inside non-directive controller function

  6. 6

    Getting an attribute value from a directive's isolated controller

  7. 7

    Set string as directive attribute value that maps to a member on the controller scope

  8. 8

    Passing a variable as ngModel to attribute directive

  9. 9

    Passing Boolean Value Into Directive

  10. 10

    AngularJs passing a value to a directive

  11. 11

    AngularJs passing a value to a directive

  12. 12

    Value not passing to directive - AngularJS

  13. 13

    AngularJS value not passing to directive

  14. 14

    Passing values from directive to controller

  15. 15

    passing values to controller from directive

  16. 16

    get directive attribute defined in HTML in directive controller

  17. 17

    Pass directive attribute into linked controller?

  18. 18

    Pass directive attribute into linked controller?

  19. 19

    Angular attribute directive value

  20. 20

    Passing a function as an attribute value

  21. 21

    AngularJS: passing boolean value to directive

  22. 22

    datetimepicker not passing value to Controller

  23. 23

    View Controller value passing

  24. 24

    Passing literal attribute values to angular js directive

  25. 25

    Problems with passing callback from controller to directive

  26. 26

    AngularJS controller variable not passing to child directive

  27. 27

    Passing data from directive to parent scope controller

  28. 28

    Angular Directive bind function with & not passing arguments to controller

  29. 29

    Passing variable from controller scope to directive

HotTag

Archive