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"

最新文章

  1. SQL SERVER 属性OWNER不可用于数据库xxx。该对象可能没有此属性,也可能是访问权限不足而无法检索。
  2. wpf图片查看器,支持鼠标滚动缩放拖拽
  3. java时间类型的转换/获取当前时间/将时间转换成String/将String转换成时间
  4. Android系列之网络(一)----使用HttpClient发送HTTP请求(通过get方法获取数据)
  5. Delphi Xe 中如何把日期格式统一处理,玩转 TDatetime
  6. Java中常见数据结构:list与map
  7. [转载] Go语言并发之美
  8. phpwind8.7升级9.0.1过程(二)8.7正式升级9.0
  9. android之蓝牙设备的使用01
  10. Excel 绘制图表,如何显示横轴的数据范围
  11. 转: Oracle AWR 报告 每天自动生成并发送邮箱
  12. UVA 10317 - Equating Equations (背包)
  13. Android UI布局TableLayout
  14. ISAPI_Rewrite不起作用的N种原因
  15. javap反编译命令详解&amp;Eclipse中配置javap命令
  16. python 练习2
  17. foreach 引用传值&amp;
  18. the secrets
  19. redis5 集群迁移方案
  20. SkylineGlobe 邻近度(Proximity)分析JavaScript源代码

热门文章

  1. 初拾Java(问题三:乱码问题)
  2. LongAdder &amp; AtomicInteger
  3. 转载:tar命令批量解压方法总结
  4. javascript入门教程笔记
  5. [APIO2018]铁人两项 --- 圆方树
  6. maven搭建企业级多模块项目
  7. Codeforces Beta Round #9 (Div. 2 Only) B. Running Student 水题
  8. HDU 5296 Annoying problem dfs序 lca
  9. Codeforces Round #303 (Div. 2) D. Queue 傻逼题
  10. 使用Mysql慢查询日志对有效率问题的SQL进行监控