最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

AngularJS 遇到的小坑與技巧小結(jié)

 更新時(shí)間:2016年06月07日 09:33:16   作者:coolicer  
本文主要對(duì)AngularJS 遇到的小坑與技巧進(jìn)行了一個(gè)小小的總結(jié),比較使用,希望能給大家做一個(gè)參考。

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:

復(fù)制代碼 代碼如下:
<div ng-bind-html="preview_data.preview.embed.htmlSafe"></div>

In your controller, inject the $sce service, and mark the HTML as "trusted":

復(fù)制代碼 代碼如下:
myApp.controller('myCtrl', ['$scope', '$sce', function($scope, $sce) {
  // ...
  $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)文章

最新評(píng)論

祁门县| 安庆市| 哈尔滨市| 油尖旺区| 上饶市| 墨竹工卡县| 乌恰县| 黄大仙区| 辽源市| 铜陵市| 辽源市| 类乌齐县| 南郑县| 巨野县| 墨竹工卡县| 神农架林区| 松滋市| 蒲江县| 灵丘县| 申扎县| 卢氏县| 贡觉县| 仲巴县| 锡林浩特市| 台前县| 岳池县| 栖霞市| 孙吴县| 万安县| 雷波县| 临清市| 台湾省| 方城县| 阜城县| 三台县| 霍山县| 曲阳县| 永善县| 昌乐县| 定日县| 阜平县|