V
V
vasIvas2015-09-08 15:35:15
Angular
vasIvas, 2015-09-08 15:35:15

How to get model in directive?

When initialized, the model makes a request to the server and receives data. This data must be parsed in the directive in order to build a dynamic menu. How should the model get into the directive? If it has to get into the directive through the controller of the directive, how should it get into it? And I have heard more than once that using ngRepeat in a template directive is bad, just like having both a controller and a link at the same time. This makes my brain explode.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-09-08
@vasIvas

This data must be parsed in the directive in order to build a dynamic menu.

they must be parsed in the service, that is, in your model. And then this tree or whatever else in the controller can be converted to the view format.
class FooController {
    constructor(fooService) {
        this.fooService = fooService;
    }
}

return {
    controller: FooController,
    controllerAs: 'vm',
    link: function (scope, el, attr, ctrl) {
         
    }
}

or inject the service into a directive.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question