[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 ...
随机推荐
- MySQL_PHP学习笔记_2015_0923_MySQL如何开启事件
1. 查看事件状态>>>>>>>>>>>>>>>>>>>>>>> ...
- 线程局部变量ThreadLocal的原理及使用范围_1
线程局部变量ThreadLocal的原理及使用范围 使用原理 每个Thread中都有一个ThreadLocalMap成员, 该成员是ThreadLocal的内部类ThreadLocalMap类型.每使 ...
- kali install fcitx
1 卸载fcitx相关软件包 如果系统安装了fcitx相关东西,需要卸载,因为源的fcitx版本太低.请谨慎,后果自负. apt-get purge fcitx-* 2 手动下载最新的fcitx软件包 ...
- Linux下的GitHub安装与简单配置教程
1.GitHub简介 Git是一个分布式版本控制系统,与其相对的是CVS.SVN等集中式的版本控制系统. 2.Git的安装 1)安装Git a.查看与使用 在ubuntu下可以使用如下命令进行查看系统 ...
- java多线程之synchronized(线程同步)
一.线程同步,主要应用synchronized关键字: public class TraditionalThreadSynchorinzed { public static void main(Str ...
- 编译python3
安装环境 yum install gcc yum install zlib-devel yum install make 下载python版本 wget http://www.python.org/f ...
- ssh-keygen
- 第二百二十五 how can I 坚持
今天感觉好累啊,心累,上班连开两个会.事情乱七八糟,接二连三. 住的这噪音还那么大. 哎. 睡觉吧.
- Cocos2d-x项目移植到WP8小记
Cocos2d-x项目移植到WP8小记 作者: K.C. 日期: 10/24/2013 Date: 2013-10-24 00:33 Title: Cocos2d-x项目移植到WP8小记 Tags: ...
- http://blogs.msdn.com/b/pranavwagh/archive/2007/03/03/word-2007-file-seems-to-be-deleted-when-you-open-and-save-it-using-dsoframer.aspx
http://blogs.msdn.com/b/pranavwagh/archive/2007/03/03/word-2007-file-seems-to-be-deleted-when-you-op ...