[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-appand 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-hintmodule:
<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 ...
随机推荐
- keil中的memory model
这两天仿真遇到的怪事真的是一大堆. 还是读写Flash的代码.keil编译OK,但是仿真就是莫名其妙地挂掉出现一些乱七八糟的事情. 后面发现是keil 中的memory model勾选错了,勾选的是l ...
- iOS 9音频应用播放音频之第一个ios9音频实例
iOS 9音频应用播放音频之第一个ios9音频实例 第一个ios9音频实例 为了让开发者可以对上面的内容有更加深入的了解,本节将实现播放音频的第一个实例.在此实例中会涉及到项目的创建.界面设计.关联以 ...
- python 爬虫 User-Agent
USER_AGENTS = [ "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chro ...
- 「NOIP2018」保卫王国
「NOIP2018保卫王国」 题目描述 有一棵 \(n\) 个点, 点有点权 \(a_i\),\(m\) 组询问, 每次求钦点两个节点必须选或者必须不选后的树上最小点覆盖. \(1 \leq n, m ...
- HDU 6071 Lazy Running(最短路)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=6071 [题目大意] 给出四个点1,2,3,4,1和2,2和3,3和4,4和1 之间有路相连, 现在 ...
- servlet3.0 @WebServlet注解无效的情况
web.xml文件中的metadata-comcomplete属性的作用: 该属性指定当前的部署描述文件是否是完全的.如果设置为true,则容器在部署时只依赖部署描述文件,忽略所有的注解(同时也会跳过 ...
- [转]JSONObject,JSONArray使用手册
您的评价: 收藏该经验 这两个是官网的API JSONObject API JSONArray API 里面有这两个类的所有方法,是不可多得的好材料哦~ 配合上面的API ...
- MySQL之char、varchar和text的设计
最近有表结构设计中出现了varchar(10000)的设计引起了大家的讨论,我们下面就来分析分析. 首先我们先普及一下常识: 1.char(n)和varchar(n)中括号中n代表字符的个数,并不代表 ...
- Struts2 @ResultPath注释示例
在Struts 2中, @ResultPath 注解用于控制Struts2找到存储的结果或JSP页面.默认情况下,它会找到结果页在 “WEB-INF/content/” 文件夹. 不知道为什么在Str ...
- PHP str_pad() 函数
str_pad() 函数把字符串填充为指定的长度. 进入 详细介绍页面