AngularJS 遇到的小坑與技巧小結
1. templateURL和路由之類的要在web server下運行。
2. 使用模板replace設為true,模板里也要有相應的標簽,否則不出現(xiàn)任何數(shù)據(jù)。
3. 1.2版本之后,ngRoute模塊獨立。
4.空的controller不定義會出錯。
5.Directive的link參數(shù)是有順序的:scope,element,attrs,ctrl
6.ng-repeat不能循環(huán)重復的對象。hack: ng-repeat="thing in things track by $id($index)"
7.盡量更新的是變量的屬性而不是單個變量本身。
8.注意ng-repeat,ng-controller等會產(chǎn)生獨立作用域。
9.當jquery載入,則使用jquery,否則使用內置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標簽沒有去掉 <a href="#" ng-click="someMethod();"></a>
11.Error: listen EACCES 當在linux下,會出現(xiàn)這個錯誤,因為你監(jiān)聽的端口的原因,這里我的是33。把它改成8080或3030之類大的端口數(shù)就可以了。有一個規(guī)定,這些端口最好是大于1024。
12. select在沒有ng-model的時候,無法顯示。同理,當遇到無法顯示最好看文檔少了什么。
補:當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服務
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的語法,大家可以關注:AngularJS 參考手冊英文版,也希望大家多多支持腳本之家。
相關文章
詳解使用angular-cli發(fā)布i18n多國語言Angular應用
這篇文章主要介紹了詳解使用angular-cli發(fā)布i18n多國語言Angular應用,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-05-05詳解JavaScript的AngularJS框架中的表達式與指令
這篇文章主要介紹了JavaScript的AngularJS框架中的表達式與指令,文中羅列了幾個常用的指令屬性加以說明,需要的朋友可以參考下2016-03-03AngularJS實現(xiàn)的base64編碼與解碼功能示例
這篇文章主要介紹了AngularJS實現(xiàn)的base64編碼與解碼功能,結合實例形式分析了AngularJS字符串base64編碼與解碼操作相關實現(xiàn)技巧,需要的朋友可以參考下2018-05-05Angularjs實現(xiàn)下拉框聯(lián)動的示例代碼
本篇文章主要介紹了Angularjs下拉框聯(lián)動的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-08-08