angularJS問題集結

來源:互聯網
上載者:User

標籤:org   ack   apply()   更新   點擊   object   amp   cti   失效   

1、用ng-repeat迴圈輸出遇到很奇怪的問題 :

Error: [ngRepeat:dupes] http://errors.angularjs.org/1.4.6/ngRepeat/dupes?p0=x%20in%20result&p1=stri…83%EF%BC%8C%E7%BB%93%E6%9E%9C%E6%98%AF%EF%BC%9A%E4%BD%A0%E8%BE%93%E4%BA%86

    at angular.min.js:6

    at angular.min.js:279

    at Object.fn (angular.min.js:129)

    at n.$digest (angular.min.js:130)

    at n.$apply (angular.min.js:133)

    at HTMLInputElement.<anonymous> (angular.min.js:253)

at HTMLInputElement.c (angular.min.js:35)

意思是指ng-repeat不能有重複資料:解決辦法:ng-repeat="keys in newlist track by $index",加track by $index,也可以 trace by 任何一個普通的值,只要能唯一性標識數組中的每一項即可

 

2、資料雙向繫結失效,就是明明在controller裡面給$scope.×××賦值了,在頁面上xxx愣是顯示不了,但是點擊一下輸入框或是form表單的提交按鈕,xxx資料資訊就顯示了。

解決辦法:添加 $scope.$apply();

$scope.$apply(function(){ 

  $scope.xxx = “你賦的值”;

});

一般情況下是不需要我們手動添加這一句代碼的,因為angularJS本身在需要的時候調用,以達到我們所看到的資料雙向繫結的效果。

但是你若是引用一個外部外掛程式或者其他,在回呼函數裡建立或更新$scope.xxx的資料,因為外部外掛程式本身已經脫離了angularJS的範圍,所以資料雙向繫結在這裡沒有效果,只能手動添加$scope.$apply()來通知頁面擷取資料。

參考網址:http://www.bdqn.cn/news/201409/15295.shtml

 

angularJS問題集結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.