AngularJS 遇到的小坑與技巧小結(jié)
1. templateURL和路由之類的要在web server下運行。
2. 使用模板replace設(shè)為true,模板里也要有相應(yīng)的標(biāo)簽,否則不出現(xiàn)任何數(shù)據(jù)。
3. 1.2版本之后,ngRoute模塊獨立。
4.空的controller不定義會出錯。
5.Directive的link參數(shù)是有順序的:scope,element,attrs,ctrl
6.ng-repeat不能循環(huán)重復(fù)的對象。hack: ng-repeat="thing in things track by $id($index)"
7.盡量更新的是變量的屬性而不是單個變量本身。
8.注意ng-repeat,ng-controller等會產(chǎn)生獨立作用域。
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下,會出現(xiàn)這個錯誤,因為你監(jiān)聽的端口的原因,這里我的是33。把它改成8080或3030之類大的端口數(shù)就可以了。有一個規(guī)定,這些端口最好是大于1024。
12. select在沒有ng-model的時候,無法顯示。同理,當(dāng)遇到無法顯示最好看文檔少了什么。
補(bǔ):當(dāng)ng-options的源,跟書寫不相配時會出現(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的語法,大家可以關(guān)注:AngularJS 參考手冊英文版,也希望大家多多支持腳本之家。
相關(guān)文章
Angular 通過注入 $location 獲取與修改當(dāng)前頁面URL的實例
這篇文章主要介紹了Angular 通過注入 $location 獲取與修改當(dāng)前頁面URL的實例代碼,需要的朋友可以參考下2017-05-05
AngularJS學(xué)習(xí)筆記之ng-options指令
ng-options是angular-1.3新出的一個指令,這篇文章就來介紹這個指令的用法.有需要的小伙伴可以參考下。2015-06-06
angular 實現(xiàn)的輸入框數(shù)字千分位及保留幾位小數(shù)點功能示例
這篇文章主要介紹了angular 實現(xiàn)的輸入框數(shù)字千分位及保留幾位小數(shù)點功能,涉及AngularJS數(shù)值運算、正則匹配等相關(guān)操作技巧,需要的朋友可以參考下2018-06-06
Angular4學(xué)習(xí)教程之HTML屬性綁定的方法
這篇文章主要給大家介紹了關(guān)于Angular4學(xué)習(xí)教程之HTML屬性綁定的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2018-01-01
深入淺析AngularJS中的一次性數(shù)據(jù)綁定 (bindonce)
這篇文章主要介紹了AngularJS中的一次性數(shù)據(jù)綁定 (bindonce)知識,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-05-05
AngularJs unit-testing(單元測試)詳解
本文主要介紹AngularJs unit-testing(單元測試)的內(nèi)容,這里整理了單元測試的知識,及示例代碼,有興趣的朋友可以參考下2016-09-09

