I
I
Ivan2015-10-25 20:13:25
Angular
Ivan, 2015-10-25 20:13:25

What's the difference how to connect modules?

Good day.
I connect the necessary modules to the controller in this way

app.controller('nameCtrl', function($scope) {
    ...
    ...
    ...

})

Is there a technical difference between connecting modules in this way?
app.controller('nameCtrl', ['$scope', function($scope) {
    ...
    ...
    ...

}])

Thanks

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
D', 2015-10-25
@ATNC

The second option is preferable.
When using minifiers in the first variant, the code will break, in the second it won't.

R
Radiks Alijevs, 2015-10-25
@dedalik

You can also use Dependency Inject, property $inject:

var nameCtrl = function($scope) {
  // ...
}
nameCtrl.$inject = ['$scope'];
app.controller('nameCtrl', nameCtrl);

V
Valeriy Donika, 2015-10-30
@Valonix

https://github.com/johnpapa/angular-styleguide There are a lot of useful and interesting things here. Before writing something, I advise you to look at best practices. Then you don't have to refactor a bunch of code :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question