[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 ...
随机推荐
- Docker应用系列(一)| 构建Redis哨兵集群
本示例基于Centos 7,在阿里云的三台机器上部署redis集群,假设目前使用的账号为release,拥有sudo权限. 由于Docker官方镜像下载较慢,可以开启阿里云的Docker镜像下载加速器 ...
- iOS 9的新的改变 iOS SDK Release Notes for iOS 9 说了些改变
iOS 9的新的改变 iOS SDK Release Notes for iOS 9 说了些改变 看了下还算能理解!!!有兴趣可以看看哈!!!不喜勿喷!!后面的对于废除的方法什么有用感觉!!! ...
- 常见http错误码
一些常见的状态码为: 200 - 服务器成功返回网页 404 - 请求的网页不存在 503 - 服务不可用 详细分解: 1xx(临时响应) 表示临时响应并需要请求者继续执行操作的状态代码. 代码 说明 ...
- python tesseract 识别图片中的文字的乱码问题(ubuntu系统下)
OCR(Optical Character Recognition):光学字符识别,是指对图片文件中的文字进行分析识别,获取的过程. 首先,需要安装 tesseract-ocr(tesseract O ...
- 使用matplotlib绘图(四)之散点图
# 使用matplotlib绘制散点图 import numpy as np import matplotlib.pyplot as plt # 设置全局刻度标签大小 plt.rcParams['xt ...
- FastReport.Net使用:[8]交叉表一
1.绘制报表标题,交叉表可以直接放在标题栏内. 2.拖动一交叉表控件到标题栏内. 3.设置交叉表的行列信息. 将Tabel中的[科室名称]列拖到交叉表的列上以创建列,将Tabel中的[姓名]列拖到交叉 ...
- [CodeForces-513E2]Subarray Cuts
题目大意: 给你一个数列,从中选出k个互不重叠的非空子串,定义s[i]为第i个子串的和,求|s[1]-s[2]|+|s[2]-s[3]|+...+|s[k-1]-s[k]|的最大值. 思路: 考虑将绝 ...
- [转]android中OnTouch和OnClick、 imagebutton的src和background有什么区别
1.OnTouch和OnClick有何区别? 专业回答 1.onClick就传入一个View对象,而 onTouch要传入一个View 对象和 MotionEvent的对象2.onTouch对控件 ...
- Codeforces Round #299 (Div. 2) B. Tavas and SaDDas 水题
B. Tavas and SaDDas Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/535/p ...
- leetcode644. Maximum Average Subarray II
leetcode644. Maximum Average Subarray II 题意: 给定由n个整数组成的数组,找到长度大于或等于k的连续子阵列,其具有最大平均值.您需要输出最大平均值. 思路: ...