A
A
artekha2017-02-13 19:37:17
JavaScript
artekha, 2017-02-13 19:37:17

What is the difference in two expressions in angular?

I saw such an example in the dock, and I can’t understand why wrap everything in an array and pass the first two elements, which are then passed to the function parameters if it works without it:

// Пример из доки
app.controller('authCtrl', ['$rootScope', '$location', function($rootScope, $location) {
  // Код
}]);
// Мой пример
app.controller('authCtrl', function($rootScope, $location) {
  // Код
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2017-02-13
@artekha

The first option will work everywhere.
The second option, if $inject is not used, will break after minification.
That's it in a nutshell =)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question