angular.js - 关于angular RouteProvider
问题描述
config([’$routeProvider’, function($routeProvider){ $routeProvider.when} ]);config(function($routeProvider){ $routeProvider.when});请问这两种方式配置路由有什么区别?
问题解答
回答1:http://www.html-js.com/article/2956
回答2:首先看文档
注意红色部分,如果不用显示指定参数的方式注入依赖,那么当你minify代码时,那些变量名可能被替换,从而导致运行时注入失败
回答3:这两种都是依赖注入的方式,ng中的3种注入方式:a、推断式注入app.controller(’MyCtrl’, function($scope) { });
b、标注式注入var myFunc=function($scope) { });myFunc.$inject = [’$scope’];app.controller(’MyCtrl’,myFunc);
c、内联注入app.controller(’MyCtrl’, [’$scope’, function($scope) {}]);
第1种是根据写的参数名称,如$scope,内部自己调用$inject把$scope进行依赖注入,如果在前端开发中使用压缩工具,就会把$scope变成另外的字母了,就无法进行推断了,而另外两种方式你可以把function($scope)改成function(a)都没关系;第2种要多写一行代码;一般推荐使用第3种。
相关文章:
1. 数据库设计 - Binary Allow Null Default mysql数据库字段属性问题 ?2. android - 求 360浏览器 百度浏览器 搜狗浏览器的最新启动类名3. PHP中的$this代表当前的类还是方法?4. html - vue如何定义一个变量,让所有组件都能使用5. php laravel框架模型作用域6. 老师,CSS3里面,选择一个DIV,这个DIV是以什么为原点进行旋转的啊?7. pdo 写入到数据库的内容为中文的时候写入乱码8. javascript - JS用ajax爬取百度外卖店家信息9. mysql每隔10来秒就有一次7、8MB的写入10. javascript - 微信提现页面的键盘怎么做的