0

I want to create a custom directive that is an attribute that requires an attribute value similar to how ng-repeat takes a list of items. For example,

<div myDir="{{someList}}"></div>

How is this done?

d1du
  • 296
  • 1
  • 3
  • 12
  • see this http://stackoverflow.com/questions/16546771/how-do-i-pass-multiple-attributes-into-an-angular-js-attribute-directive – Hadi J Jul 03 '16 at 06:52

1 Answers1

0

You should do it like this

app.directive('myDir', function () {
    return {
        scope: {
            'myDir' : '@', //'@' for evaluated value of the DOM attribute, 
                           //'=' a parent scope property
        },
        link: function (scope, element, attrs) {
            scope.$watch('myDir', function (newVal) {
                console.log('myDir', newVal);
            });
        }
    };
});

usage for evaluated value (with '@')

<div my-dir="{{someList}}"></div>

usage for property from a scope (with '=')

<div my-dir="someList"></div>

to understand difference between '@' and '=' look here

Community
  • 1
  • 1
BotanMan
  • 1,357
  • 12
  • 25