angular.js - angularjs中,带个[]是什么意思?
高洛峰
高洛峰 2017-05-15 17:00:43
0
2
456
app.factory('Notes', ['$resource', function($resource) {
    return $resource('/notes/:id', null, {
        update: { method:'PUT' }
    }); 
}]);

貌似上面这种写法跟下面这种没差别。请问有什么差别??

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

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(2)
曾经蜡笔没有小新

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

Ty80

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!