0
    app.directive('myCustomAttr',function() {
    return {
        restrict: 'A',
        scope: {
            valueOfAttr : "@myCustomAttr"
        },
      };
});

How would I pass the value of the attribute? Thus far, I've only found examples that use restrict : 'E'.

<input type="text" my-custom-attr="myValue" />

So, if I were going to bind "myValue" to the scope, how would I do that?

[EDIT]

Sorry, I had a typo. I was using the my-custom-attribute correctly, but it still doesn't seem to bind in the directive.

2
  • <input type="text" my-custom-attr="myValue" /> Commented May 7, 2014 at 19:00
  • valueOfAttr : "=myCustomAttr" should provide two way binding. Not my code, see: jsfiddle.net/bcaudan/SbrKj Commented Dec 29, 2016 at 9:15

2 Answers 2

1

I'm pretty sure you want =myCustomAttr instead of @myCustomAttr. There's mention of this under "Isolating the Scope of a Directive". There's also more information here.

Sign up to request clarification or add additional context in comments.

Comments

0

use the link function:

link: function (scope, element, attrs) {
   var myAttr = attrs["myCustomAttr"];
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.