search

Home  >  Q&A  >  body text

angular.js - What does a [] mean in angularjs?

app.factory('Notes', ['$resource', function($resource) {
    return $resource('/notes/:id', null, {
        update: { method:'PUT' }
    }); 
}]);

It seems that the way of writing above is no different from the way of writing below. What's the difference? ?

app.factory('Notes', function($resource) {
    return $resource('/notes/:id', null, {
        update: { method:'PUT' }
    }); 
});
高洛峰高洛峰2784 days ago520

reply all(2)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-15 17:02:43

    This is still available after it is called inline array annotation,目的是在代码被uglify.

    You can try it. If you don’t pass [] processing and compress the code, it will definitely not run.

    Please refer to Dependency Injection for details

    reply
    0
  • PHP中文网

    PHP中文网2017-05-15 17:02:43

    There is no difference, but it is better to use the first way of writing. Because the second type is injected directly based on the formal parameters, if the code is compressed and $resource is compressed into something else, an error will be reported.

    reply
    0
  • Cancelreply