user4903029
user4903029

Reputation:

Angular directive parameter as an object

Travellers :)

Here is an example as I think directive parameters should be working, but they don't. http://jsfiddle.net/z1m3gar5/

First directive uses

.directive('myDirective1', function () {
    return {
        restrict: 'E',
        scope: {
            options: '@'
        },
        templateUrl: 'MyDirective1.html',
        controller: function ($scope) {},
    }
})
...
<div>{{ options }}</div>

The other one uses

.directive('myDirective2', function () {
    return {
        restrict: 'E',
        scope: {
            options: '='
        },
        templateUrl: 'MyDirective2.html',
        controller: function ($scope) {},
    }
})
...
<div>{{ options.param }}</div>

First definition works just fine, the second doesn't. What do I miss? Thanks

Upvotes: 1

Views: 38

Answers (1)

Yashika Garg
Yashika Garg

Reputation: 2366

You are using two-way binding for directive2 and for this you are not require to use {{ }}.

<my-directive2 options="dir2"></my-directive2>

and it will work fine!

Here is updated jsFiddle

Upvotes: 1

Related Questions