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:

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-hintmodule:

<body ng-app="myApp" ng-hint>
</body>

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

  1. [Angularjs]angular ng-repeat与js特效加载先后导致的问题

    写在前面 最近在项目中遇到这样的一个前端的bug,在ng-repeat中绑定的图片,有一个晃动的特效,在手机端浏览的时候,图片有时候会正常展示,有时就展示不出来.当时猜测是因为angularjs与特效 ...

  2. [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 ...

  3. [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 ...

  4. [AngularJS] Angular 1.3 ng-model-options - getterSetter

    getterSetter:  boolean value which determines whether or not to treat functions bound to ngModel as ...

  5. [AngularJS] Angular 1.3: ng-model-options updateOn, debounce

    <!DOCTYPE html> <html ng-app="app"> <head lang="en" > <meta ...

  6. AngularJs angular.identity和angular.noop详解

    angular.identity 函数返回本身的第一个参数.这个函数一般用于函数风格. ----------以上是官网对该接口的说明,只能说这个文档写得也太二,让人完全看不懂.要理解它的用途,可直接看 ...

  7. AngularJs angular.Module模块接口配置

    angular.Module Angular模块配置接口. 方法: provider(name,providerType); name:服务名称. providerType:创建一个服务的实例的构造函 ...

  8. AngularJs Angular数据类型判断

    angular.isArray 判断括号内的值是否为数组. 格式:angular.isArray(value); value: 被判断是否为数组的值. ------------------------ ...

  9. AngularJs angular.injector、angular.module

    angular.injector 创建一个injector对象, 调用injector对象的方法可用于获取服务以及依赖注入. 格式:angular.injector(modules); modules ...

随机推荐

  1. Docker入门到实战

    1.系统要求 Docker CE 支持 64 位版本 CentOS 7,并且要求内核版本不低于 3.10. CentOS 7满足最低内核的要求,但由于内核版本比较低,部分功能(如 overlay2 存 ...

  2. Java常用工具类之删除文件

    package com.wazn.learn.util; import java.io.File; /** * 删除文件工具类 * @author yangzhenyu * */ public cla ...

  3. javascript入门教程笔记

    BOM BOM 是“ Browser Object Model ”的缩写,简称“ 浏览器对象模型 ”. BOM 定义了 JavaScript 操作浏览器的接口,提供了访问某些功能(如浏览器窗口大小.版 ...

  4. code forces 505A

    Mr. Kitayuta's Gift Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64 ...

  5. C++ STL 全排列函数详解

    一.概念 从n个不同元素中任取m(m≤n)个元素,按照一定的顺序排列起来,叫做从n个不同元素中取出m个元素的一个排列.当m=n时所有的排列情况叫全排列.如果这组数有n个,那么全排列数为n!个. 比如a ...

  6. UESTC 2015dp专题 F 邱老师看电影 概率dp

    邱老师看电影 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/65 Descr ...

  7. 类方法load和initialize的区别

    1.+load方法当类或分类添加到object-c runtime时被调用,子类的+load方法会在它所有父类的+load方法之后执行,而分类的+load方法会在它的主类的+load方法之后执行.但不 ...

  8. HashSet,TreeSet和LinkedHashSet

    Set接口 Set不允许包含相同的元素,如果试图把两个相同元素加入同一个集合中,add方法返回false. Set判断两个对象相同不是使用==运算符,而是根据equals方法.也就是说,只要两个对象用 ...

  9. SQL Server 2008 Windows身份验证改为混合模式身份验证 及修改sa密码

    由于需要,要把SQL2008单一的Windows身份验证改为混合模式身份验证.在此做一备忘. 步骤: 1.用Windows身份验证方式进入SQL2008,在[对象资源管理器]右键击[根目录]:

  10. [Asp.net]DropDownList改变默认选中项的两种方式

    引言 其实是不想总结这方面的内容,发现太简单了,可是在这上面也栽了跟头.所以还是记录一下吧,算是提醒自己,不要太看不起太基础的东西,有这种心理,是会载大跟头的. 一个例子 这里模拟一下最常用的一个例子 ...