博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[AngularJS] Best Practise - Minification and annotation
阅读量:5098 次
发布时间:2019-06-13

本文共 1343 字,大约阅读时间需要 4 分钟。

Annotation Order:

It's considered good practice to dependency inject Angular's providers in before our own custom ones.

Bad:

// randomly ordered dependenciesfunction SomeCtrl (MyService, $scope, AnotherService, $rootScope) {}

Good:

// ordered Angular -> customfunction SomeCtrl ($scope, $rootScope, MyService, AnotherService) {}

 

Minification methods, automate it

Use ng-annotate for automated dependency injection annotation, as ng-min is .

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 wastingSomeService.$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) {}// automatedSomeService.$inject = ['$scope'];angular  .module('app')  .factory('SomeService', SomeService);

 

转载于:https://www.cnblogs.com/Answer1215/p/4121450.html

你可能感兴趣的文章
BZOJ1045 HAOI2008 糖果传递
查看>>
JavaScript 克隆数组
查看>>
python3 生成器与迭代器
查看>>
git .gitignore 文件不起作用
查看>>
digitalocean --- How To Install Apache Tomcat 8 on Ubuntu 16.04
查看>>
【题解】[P4178 Tree]
查看>>
cer证书签名验证
查看>>
【深度学习】caffe 中的一些参数介绍
查看>>
QML学习笔记之一
查看>>
App右上角数字
查看>>
小算法
查看>>
新作《ASP.NET MVC 5框架揭秘》正式出版
查看>>
WPF中实现多选ComboBox控件
查看>>
读构建之法第四章第十七章有感
查看>>
Windows Phone开发(4):框架和页 转:http://blog.csdn.net/tcjiaan/article/details/7263146
查看>>
python asyncio 异步实现mongodb数据转xls文件
查看>>
TestNG入门
查看>>
【ul开发攻略】HTML5/CSS3菜单代码 阴影+发光+圆角
查看>>
IOS-图片操作集合
查看>>
IO—》Properties类&序列化流与反序列化流
查看>>