[AngularJS] Angular 1.3 Anuglar hint
2014-11-08 23:41
225 查看
Read More: http://www.linkplugapp.com/a/953215
https://docs.google.com/document/d/1XXMvReO8-Awi1EZXAXS4PzDzdNvV6pGcuaF4Q9821Es/pub
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
Install and using
Once it’s installed, we can embed the source in our application right after Angular itself like this:
Next, we apply the
By default,
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
The following code only injects
We can even define more than just one hint module if needed:
but forgot to include into your main app:
Now, instead of fiddling around for an hour to find out why
Having a controller registered like this,
However, when
https://docs.google.com/document/d/1XXMvReO8-Awi1EZXAXS4PzDzdNvV6pGcuaF4Q9821Es/pub
angular-hinthelps 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-hintdirective in order to actually use the
angular-hintmodule:
<body ng-app="myApp" ng-hint> </body>
By default,
ng-hintinjects 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-includedirective 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-hintis 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 withControllerinstead of using short names like
Ctrl.
angular-hinthelps 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-hintgives 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-hintis 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 ng-model-options - getterSetter
- [AngularJS] Angular 1.3 ngMessages with ngAnimate
- [AngularJS] Test an Angular Component with $componentController
- [AngularJS] Using an AngularJS directive to hide the keyboard on submit
- [AngularJS] Angular 1.3 new $q constructor
- [D3 + AngularJS] 15. Create a D3 Chart as an Angular Directive
- [AngularJS] Angular 1.3: ng-model-options updateOn, debounce
- [AngularJS] Angular 1.3 $submitted for Form in Angular
- [AngularJS] New in Angular 1.3 - Performance Boost with debugInfoEnabled
- [AngularJS] Angular1.3 ngAria - 1
- [AngularJS] New in Angular 1.3 - bindToController
- [AngularJS] Angular 1.3 ngAria - 2
- Ionic/Angular TypeScript 错误:Object prototype may only be an Object or null: undefined的解决办法
- 走进AngularJs(一)angular基本概念的认识与实战
- uva 12301 - An Angular Puzzle(几何)
- android 在布局文件中报错:This text field does not specify an inputType or a hint
- [Angular] Creating an Observable Store with Rx
- ng1.3+表单验证<AngularJs>
- EditText:This text field does not specify an inputType or a hint
- [AngularJS] Using Services in Angular Directives