[AngularJS] Angular 1.3 Anuglar hint
Read More: http://www.linkplugapp.com/a/953215
https://docs.google.com/document/d/1XXMvReO8-Awi1EZXAXS4PzDzdNvV6pGcuaF4Q9821Es/pub
angular-hint
helps us writing better Angular code and makes finding very common mistakes in our code base easier. For example, did it ever happen to you, that you developed your Angular app, you grabbed a module from somewhere, then you started using the directives that the module comes with, and no matter how much you followed the usage instructions, it simply didn’t work. And after one hour of debugging you found out that you forgot to add the module dependency to your application. Yikes!
These modules are:
- angular-hint-controllers - Warns about use of global controllers and hints about best practices for controller naming
- angular-hint-directives - Hints about misspelled attributes and tags, directives and more
- angular-hint-dom - Warns about use of DOM APIs in controllers
- angular-hint-events - Identifies undefined variables in event expressions
- angular-hint-interpolation - Notifies of undefined parts of interpolations chains and suggests available variables
- angular-hint-modules - Identifies missing module namespaces, undeclared modules, multiple uses of
ng-app
and more
Install and using angular-hint
npm install angular-hint
Once it’s installed, we can embed the source in our application right after Angular itself like this:
<script type="path/to/angular/angular.js"></script>
<script type="path/to/angular-hint/hint.js"></script>
Next, we apply the ng-hint
directive in order to actually use the angular-hint
module:
<body ng-app="myApp" ng-hint>
</body>
By default, ng-hint
injects all the mentioned hint modules.
However, if we don’t want to get controller related hints, but are interested in DOM related hints, we can restrict the use of hint modules by using the ng-hint-include
directive instead.
The following code only injects angular-hint-dom
:
<body ng-app="myApp" ng-hint-include="dom">
</body>
We can even define more than just one hint module if needed:
<body ng-app="myApp" ng-hint-include="dom directives">
</body>
Module hints
If you declared an module:
angular.module('myAppDependency', []);
but forgot to include into your main app:
angular.module('myApp', []);
Now, instead of fiddling around for an hour to find out why myAppDependency
’s directives aren’t picked up, angular-hint
is telling us that we might missed something. Simply open your browsers console and you should see something like this:
Angular Hint: Modules
Module "myAppDependency" was created but never loaded.
Controller hints
One of these best practices is, when naming controllers, to suffix them with Controller
instead of using short names like Ctrl
. angular-hint
helps with that too. Let’s take a look what happens when we define a controller with a name that doesn’t have this suffix:
angular.module('myApp', []).controller('AppCtrl', function () { });
Having a controller registered like this, angular-hint
gives us the following warning:
Angular Hint: Controllers
The best practice is to name controllers ending with 'Controller'.
Check the name of 'AppCtrl'
Directive hints
Example where error might happens:
<ul>
<li ng-repaet="i in [1,2,3,4]">
<!-- more dom goes here -->
</li>
</ul>
However, when angular-hint
is activated, we get the following very useful warning:
Angular Hint: Directives
There was an AngularJS error in LI element.
Found incorrect attribute "ng-repaet" try "ng-repeat"
[AngularJS] Angular 1.3 Anuglar hint的更多相关文章
- [Angularjs]angular ng-repeat与js特效加载先后导致的问题
写在前面 最近在项目中遇到这样的一个前端的bug,在ng-repeat中绑定的图片,有一个晃动的特效,在手机端浏览的时候,图片有时候会正常展示,有时就展示不出来.当时猜测是因为angularjs与特效 ...
- [AngularJS] Angular 1.3 ngMessages with ngAnimate
Note: Can use $dirty to check whether user has intracted with the form: https://docs.angularjs.org/a ...
- [AngularJS] Angular 1.3 $submitted for Form in Angular
AngularJS 1.3 add $submitted for form, so you can use $submitted to track whether the submit event ...
- [AngularJS] Angular 1.3 ng-model-options - getterSetter
getterSetter: boolean value which determines whether or not to treat functions bound to ngModel as ...
- [AngularJS] Angular 1.3: ng-model-options updateOn, debounce
<!DOCTYPE html> <html ng-app="app"> <head lang="en" > <meta ...
- AngularJs angular.identity和angular.noop详解
angular.identity 函数返回本身的第一个参数.这个函数一般用于函数风格. ----------以上是官网对该接口的说明,只能说这个文档写得也太二,让人完全看不懂.要理解它的用途,可直接看 ...
- AngularJs angular.Module模块接口配置
angular.Module Angular模块配置接口. 方法: provider(name,providerType); name:服务名称. providerType:创建一个服务的实例的构造函 ...
- AngularJs Angular数据类型判断
angular.isArray 判断括号内的值是否为数组. 格式:angular.isArray(value); value: 被判断是否为数组的值. ------------------------ ...
- AngularJs angular.injector、angular.module
angular.injector 创建一个injector对象, 调用injector对象的方法可用于获取服务以及依赖注入. 格式:angular.injector(modules); modules ...
随机推荐
- 洛谷P3402 【模板】可持久化并查集 [主席树,并查集]
题目传送门 可持久化并查集 n个集合 m个操作 操作: 1 a b 合并a,b所在集合 2 k 回到第k次操作之后的状态(查询算作操作) 3 a b 询问a,b是否属于同一集合,是则输出1否则输出0 ...
- 实验 Unity Linear Color Space 发现结果不符合预期
美术前上个礼拜找我问光照图总是烘焙过暗的问题,一时兴起我在 Gamma 和 Linear 两个颜色空间切换了下,发现一个 Shader 明暗不同,另一个 毫无变化,于是激发了我去研究下在 Unity ...
- MYSQL注入天书之开天辟地
MYSQL注入天书 在线版本:xianzhi.aliyun.com 第一篇地址:https://xianzhi.aliyun.com/forum/read/314.html第二篇地址:https:// ...
- [BZOJ4240]有趣的家庭菜园(贪心+树状数组)
最后数列一定是单峰的,问题就是最小化最后的位置序列的逆序对数. 从大到小加数,每次贪心看放左边和右边哪个产生的逆序对数更少,树状数组即可. 由于大数放哪对小数不产生影响,所以正确性显然. 注意相同数之 ...
- [BZOJ4872][六省联考2017]分手是祝愿(期望DP)
4872: [Shoi2017]分手是祝愿 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 516 Solved: 342[Submit][Statu ...
- HDU3853 LOOPS 期望DP 简单
http://acm.hdu.edu.cn/showproblem.php?pid=3853 有一点坑的地方是如果一个地方停在原地的概率为1,那么该地的期望为0,就相当于这个地方也是一个出口... ...
- PHP配置文件经典漏洞
phithon师父在小蜜圈里放了一个经典的配置文件写入问题漏洞. <?phpif(!isset($_GET['option'])) die();$str = addslashes($_GET[' ...
- [UOJ30]/[CF487E]Tourists
[UOJ30]/[CF487E]Tourists 题目大意: 一个\(n(n\le10^5)\)个点\(m(m\le10^5)\)条边的无向图,每个点有点权.\(q(q\le10^5)\)次操作,操作 ...
- hdu 4284 状态压缩dp
题意: 有N 个点的无向图,要去其中 h个地点做事,做事需要先办理护照,之后可以挣一定数量的钱,知道了一开始有的总钱数,和 一些城市之间 道路的花费,问可不可以在 指定的 h 个城 ...
- git -- git clone
git clone 命令参数: usage: git clone [options] [--] <repo> [<dir>] -v, --verbose be more ver ...