H
H
hobu4ok912016-06-20 11:55:33
Angular
hobu4ok91, 2016-06-20 11:55:33

How in Angular js to use an object in its directive passed through ng-model?

For example there is
<my-directive ng-model="object"></my-directive>
How to get this object in a directive to use for example:

.directive('myDirective', function(){
return {
    template: '<div>{{object.elem1}}</div>'
}
})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DarthJS, 2016-06-30
@DarthJS

I don't really understand why you do that, here's the answer:

return {
    template: '<div>{{elem1}}</div>',
  link: function(scope, el, attrs){
  scope.elem1 = attrs.ngModel;
}
}

Second option:
return {
    template: '<div>{{obj.elem1}}</div>',
 scope: {
  obj: '='
},
link: function(scope, el, attrs){
}
}

Fix it. if something is wrong

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question