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的更多相关文章

  1. [AngularJS] Best Practise - Module

    Module definitions Angular modules can be declared in various ways, either stored in a variable or u ...

  2. [AngularJS] Best Practise - Controller

    ControllerAs: Use thecontrollerAs syntax always as it aids in nested scoping and controller instance ...

  3. [AngularJS] Best Practise - Resolve promises in router, defer controllers

    See more:http://toddmotto.com/opinionated-angular-js-styleguide-for-teams/ /** * Created by Answer12 ...

  4. Best Practice AngularJS

    Best Practice AngularJS /* 用几组简明扼要的代码段及其说明, 展示良好的编程行为, angularjs */ // app.module.js angular .module ...

  5. 转: angular编码风格指南

    After reading Google's AngularJS guidelines, I felt they were a little too incomplete and also guide ...

  6. AngularJS之ng-options的best practise

    废话不多说,直接上代码. function MySelectCtrl($scope) { $scope.Model = [ { id: 10002, MainCategory: '男', Produc ...

  7. Angularjs 源码

    /** * @license AngularJS v1.3.0-beta.15 * (c) 2010-2014 Google, Inc. http://angularjs.org function t ...

  8. 玩转spring boot——结合AngularJs和JDBC

    参考官方例子:http://spring.io/guides/gs/relational-data-access/ 一.项目准备 在建立mysql数据库后新建表“t_order” ; -- ----- ...

  9. 玩转spring boot——结合jQuery和AngularJs

    在上篇的基础上 准备工作: 修改pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=&q ...

随机推荐

  1. MVC同一个视图多个submit对应不同action

    Vi ew中代码 <input type="submit" value="yes" name="action"> <inp ...

  2. the NTP socket is in use, exiting

    centos下使用如下命令手动同步服务器时间 ntpdate ntp.fudan.edu.cn 或 ntpdate ntp.api.bz 出现“the NTP socket is in use, ex ...

  3. Cloudera Manager5安装总结遇到问题及解决办法

    安装过程中,由于网络终端,导致下面问题: 问题1:安装停止在获取安装锁/tmp/scm_prepare_node.tYlmPfrT using SSH_CLIENT to get the SCM ho ...

  4. 本人为项目组制定的一份页面优化指南(easyui页面优化方案)

    #本人为项目组制定的一份页面优化指南(easyui页面优化方案) ##背景 这是一篇我之前为项目组制定的页面优化指南,主要是面向表单页面,典型的像[注册用户](https://passport.cnb ...

  5. Java WEB —— XML

    XML语言(可扩展标记语言W3C):描述一系列有关系的数据,允许自定义标签,它常用作软件配置文件,以描述程序模块之间的关系. XML语法:文档声明,元素,注释(DATA区,特殊字符,处理指令(proc ...

  6. Mapreduce执行过程分析(基于Hadoop2.4)——(三)

    4.4 Reduce类 4.4.1 Reduce介绍 整完了Map,接下来就是Reduce了.YarnChild.main()—>ReduceTask.run().ReduceTask.run方 ...

  7. Context3D 不可用

    打开项目文件夹中的html-template,并找到index.template.html,右键使用TextEditor编辑,在params.allowfullscreen=”true”:后面加上pa ...

  8. mysql基础知识(4)--修改

    修改表: 一般概述 通常,创建一个表,能搞定(做到)的事情,修改表也能做到.大体来说,就可以做到: 增删改字段: 增:alter  table  表名  add  [column]  字段名  字段类 ...

  9. CXF整合Spring发布WebService实例

    一.说明: 上一篇简单介绍了CXF以及如何使用CXF来发布一个简单的WebService服务,并且介绍了客户端的调用. 这一篇介绍如何使用CXF与spring在Web项目中来发布WebService服 ...

  10. Pylint

    [Pylint] pylint的调用命令: pylint [options] module_or_package 使用 Pylint 对一个模块 module.py 进行代码检查: 1. 进入这个模块 ...