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

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

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

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)簽沒(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之類大的端口數(shù)就可以了。有一個(gè)規(guī)定,這些端口最好是大于1024。

12. select在沒(méi)有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:

復(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)論

新泰市| 新源县| 牟定县| 历史| 隆尧县| 全南县| 青冈县| 托克托县| 常山县| 陵川县| 西城区| 达州市| 北安市| 纳雍县| 全州县| 内丘县| 莱州市| 丰台区| 兴和县| 苍南县| 贵阳市| 札达县| 昌平区| 磐石市| 梁河县| 民丰县| 杭州市| 阳春市| 若尔盖县| 紫阳县| 民和| 邹城市| 临海市| 盘山县| 和平县| 乐山市| 惠水县| 黔西县| 临沂市| 高邮市| 星子县|