D
D
dweebAnJs2016-12-13 16:04:52
Angular
dweebAnJs, 2016-12-13 16:04:52

Why does only the third of the three controller initialization options work?

link to example
in app.js file
68caaa93e69221e0a5a0b99b38e1462e.png
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Drapeza, 2016-12-13
@dweebAnJs

None of the options really work.
It's just that your directive receives the mailListCtrl function as a controller, which you declared in option 3.
Wrap the controller name in quotes:

mailApp.directive('mailList', function(){
    return {
        restrict: 'E',
        templateUrl: 'mailListDirective.html',
        controller: 'mailListCtrl',
        // replace: true,
        controllerAs: 'mailListCtrl'
    };
});

It's even better if you start using components introduced in Angular 1.5+
And here is a starter template using webpack for assembly and ES6 syntax, this is what a modern Angular 1 application looks like.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question