[AngularJS] Best Practise - Minification and annotation
Annotation Order:
It's considered good practice to dependency inject Angular's providers in before our own custom ones.
Bad:
// randomly ordered dependencies
function SomeCtrl (MyService, $scope, AnotherService, $rootScope) { }
Good:
// ordered Angular -> custom
function SomeCtrl ($scope, $rootScope, MyService, AnotherService) { }
Minification methods, automate it
Use ng-annotate for automated dependency injection annotation, as ng-min is deprecated.
With our function declarations outside of the module references, we need to use the @ngInject comment to explicitly tell ng-annotate where to inject our dependencies. This method uses $inject which is faster than the Array syntax.
Manually specifiying the dependency injection arrays costs too much time.
Bad:
function SomeService ($scope) {
}
// manually declaring is time wasting
SomeService.$inject = ['$scope'];
angular
.module('app')
.factory('SomeService', SomeService);
Good:
// Using the ng-annotate keyword @ngInject to instruct things that need annotating: /**
* @ngInject
*/
function SomeService ($scope) { }
angular
.module('app')
.factory('SomeService', SomeService);
Will produce:
/**
* @ngInject
*/
function SomeService ($scope) { }
// automated
SomeService.$inject = ['$scope'];
angular
.module('app')
.factory('SomeService', SomeService);
[AngularJS] Best Practise - Minification and annotation的更多相关文章
- [AngularJS] Best Practise - Module
Module definitions Angular modules can be declared in various ways, either stored in a variable or u ...
- [AngularJS] Best Practise - Controller
ControllerAs: Use thecontrollerAs syntax always as it aids in nested scoping and controller instance ...
- [AngularJS] Best Practise - Resolve promises in router, defer controllers
See more:http://toddmotto.com/opinionated-angular-js-styleguide-for-teams/ /** * Created by Answer12 ...
- Best Practice AngularJS
Best Practice AngularJS /* 用几组简明扼要的代码段及其说明, 展示良好的编程行为, angularjs */ // app.module.js angular .module ...
- 转: angular编码风格指南
After reading Google's AngularJS guidelines, I felt they were a little too incomplete and also guide ...
- AngularJS之ng-options的best practise
废话不多说,直接上代码. function MySelectCtrl($scope) { $scope.Model = [ { id: 10002, MainCategory: '男', Produc ...
- Angularjs 源码
/** * @license AngularJS v1.3.0-beta.15 * (c) 2010-2014 Google, Inc. http://angularjs.org function t ...
- 玩转spring boot——结合AngularJs和JDBC
参考官方例子:http://spring.io/guides/gs/relational-data-access/ 一.项目准备 在建立mysql数据库后新建表“t_order” ; -- ----- ...
- 玩转spring boot——结合jQuery和AngularJs
在上篇的基础上 准备工作: 修改pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=&q ...
随机推荐
- bzoj1833 digit
这道题其实挺水,只是写的时候需要想清楚.我的方法是: 1.将[a,b]转化为[0,b+1)-[0,a) 2.预处理出非0的v在区间[0,10^p)出现次数以及0在区间[0,10^p)出现数 3.将一个 ...
- Code-first示例
首先创建一个空数据库 在vs2013中添加数据库类,按提示操作一直下一步 添加完以后,数据库类的代码 namespace mvctest.Models { using System; using ...
- 【boost】使用lambda表达式和generate_n生成顺序序列
程序中经常用到顺序序列(0,1,2,3,4,5,6.....),一直羡慕python有range这样的函数,而C++中通常只有用循环来处理这种初始化. 现在,结合boost库lambda(虽然差C++ ...
- linux常用的一些命令(不断增加中)
linux 下重启 apache: httpd -k restart 下面这些大多命令都可以在<鸟哥私房菜>的服务器中的“常用网络指令”和基础中的“程序与资源管理”中找到ps -aux 这 ...
- 开始使用Ambari吧
最开始接触Hadoop是研究生入学后,帮师姐装装集群什么的.过程很繁琐,很重复,很是让人抓狂.当时装一个三台机器的集群需要两天左右,这还是装的很熟练的时间花费,刚入手的时候简直是惨不忍睹,三台机器装了 ...
- 《java数据结构与算法》笔记-CH4-8栈结构实现后缀表达式计算结果
/** * 中缀表达式转换成后缀表达式: 从输入(中缀表达式)中读取的字符,规则: 操作数: 写至输出 左括号: 推其入栈 右括号: 栈非空时重复以下步骤--> * 若项不为(,则写至输出: 若 ...
- dom 左右两侧得广告(兼容IE FF)
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- easyui dialog遮罩层
当dialog在一个iframe里时,此dialog的遮罩层也会只覆盖这个iframe,要想覆盖整个页面,就把dialog写到最外层的父页面中去,此时dialog的遮罩层会自动覆盖整个页面,若需要从子 ...
- js冲突
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(//"~/Scripts/modernizr-2.6.2 ...
- 第三百三十一天 how can I 坚持
今天加了一天班,好累,还没吃晚饭,回来只吃了个泡面. 晚上回来的路上,在群里聊的倒是很happy,快笑死我了,仲宫二少,哈哈. 弟弟过两天要去见面,多聊聊,该结婚来. 还有,中午吃的肯德基,不好吃,可 ...