AngularJS 遇到的小坑與技巧小結(jié)
1. templateURL和路由之類(lèi)的要在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)簽沒(méi)有去掉 <a href="#" ng-click="someMethod();"></a>
11.Error: listen EACCES 當(dāng)在linux下,會(huì)出現(xiàn)這個(gè)錯(cuò)誤,因?yàn)槟惚O(jiān)聽(tīng)的端口的原因,這里我的是33。把它改成8080或3030之類(lèi)大的端口數(shù)就可以了。有一個(gè)規(guī)定,這些端口最好是大于1024。
12. select在沒(méi)有ng-model的時(shí)候,無(wú)法顯示。同理,當(dāng)遇到無(wú)法顯示最好看文檔少了什么。
補(bǔ):當(dāng)ng-options的源,跟書(shū)寫(xiě)不相配時(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":
// ...
$scope.preview_data.preview.embed.htmlSafe =
$sce.trustAsHtml(preview_data.preview.embed.html);
}
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è)英文版,也希望大家多多支持腳本之家。
相關(guān)文章
AngularJS中的API(接口)簡(jiǎn)單實(shí)現(xiàn)
本文主要介紹AngularJS API(接口),這里對(duì)AngularJS API的知識(shí)做了詳細(xì)講解,并附簡(jiǎn)單代碼實(shí)例,有需要的小伙伴可以參考下2016-07-07
Angular 通過(guò)注入 $location 獲取與修改當(dāng)前頁(yè)面URL的實(shí)例
這篇文章主要介紹了Angular 通過(guò)注入 $location 獲取與修改當(dāng)前頁(yè)面URL的實(shí)例代碼,需要的朋友可以參考下2017-05-05
AngularJS實(shí)現(xiàn)表單驗(yàn)證功能詳解
這篇文章主要為大家詳細(xì)介紹了AngularJS實(shí)現(xiàn)表單驗(yàn)證功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10
AngularJS學(xué)習(xí)筆記之ng-options指令
ng-options是angular-1.3新出的一個(gè)指令,這篇文章就來(lái)介紹這個(gè)指令的用法.有需要的小伙伴可以參考下。2015-06-06
angular 實(shí)現(xiàn)的輸入框數(shù)字千分位及保留幾位小數(shù)點(diǎn)功能示例
這篇文章主要介紹了angular 實(shí)現(xiàn)的輸入框數(shù)字千分位及保留幾位小數(shù)點(diǎn)功能,涉及AngularJS數(shù)值運(yùn)算、正則匹配等相關(guān)操作技巧,需要的朋友可以參考下2018-06-06
Angular4學(xué)習(xí)教程之HTML屬性綁定的方法
這篇文章主要給大家介紹了關(guān)于Angular4學(xué)習(xí)教程之HTML屬性綁定的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2018-01-01
深入淺析AngularJS中的一次性數(shù)據(jù)綁定 (bindonce)
這篇文章主要介紹了AngularJS中的一次性數(shù)據(jù)綁定 (bindonce)知識(shí),非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-05-05
AngularJs unit-testing(單元測(cè)試)詳解
本文主要介紹AngularJs unit-testing(單元測(cè)試)的內(nèi)容,這里整理了單元測(cè)試的知識(shí),及示例代碼,有興趣的朋友可以參考下2016-09-09

