1. templateURL和路由之類的要在web server下運(yùn)行。
2. 使用模板replace設(shè)為true,模板里也要有相應(yīng)的標(biāo)簽,否則不出現(xiàn)任何數(shù)據(jù)。
3. 1.2版本之后,ngRoute模塊獨(dú)立。
4.空的controller不定義會(huì)出錯(cuò)。
5.Directive的link參數(shù)是有順序的:scope,element,attrs,ctrl
6.ng-repeat不能循環(huán)重復(fù)的對(duì)象。hack: ng-repeat="thing in things track by $id($index)"
7.盡量更新的是變量的屬性而不是單個(gè)變量本身。
8.注意ng-repeat,ng-controller等會(huì)產(chǎn)生獨(dú)立作用域。
9.當(dāng)jquery載入,則使用jquery,否則使用內(nèi)置jqlite。all element references in Angular are always wrapped with jQuery or jqLite; they are never raw DOM references.
10.Uncaught Error: [$location:ihshprfx] A標(biāo)簽沒有去掉 <a href="#" ng-click="someMethod();"></a>
11.Error: listen EACCES 當(dāng)在linux下,會(huì)出現(xiàn)這個(gè)錯(cuò)誤,因?yàn)槟惚O(jiān)聽的端口的原因,這里我的是33。把它改成8080或3030之類大的端口數(shù)就可以了。有一個(gè)規(guī)定,這些端口最好是大于1024。
12. select在沒有ng-model的時(shí)候,無(wú)法顯示。同理,當(dāng)遇到無(wú)法顯示最好看文檔少了什么。
補(bǔ):當(dāng)ng-options的源,跟書寫不相配時(shí)會(huì)出現(xiàn)全部選擇的情況,如下:
var a = [{"id":1,"name":"Ryan"}....] ,ng-options="item.i as item.name for item in a" // i與id不同
----------------------------------------------------------------------------------------
13.ng-bind-html-unsafe已去除,可以用['ngSanitize'] 模塊或使用$sce服務(wù)
From stackoverflow
You indicated that you're using Angular 1.2.0... as one of the other comments indicated, ng-bind-html-unsafe has been deprecated.
Instead, you'll want to do something like this:
In your controller, inject the $sce service, and mark the HTML as "trusted":
Note that you'll want to be using 1.2.0-rc3 or newer. (They fixed a bug in rc3 that prevented "watchers" from working properly on trusted HTML.)
查看更多AngularJS的語(yǔ)法,大家可以關(guān)注:AngularJS 參考手冊(cè)英文版,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注