2017-08-21 159 views
0

以下是我的代碼。2路綁定不能按預期工作。能否請您點時的錯誤角度2路綁定不起作用

<div id="list" class="form-group"> 
      <label for="attach" class="col-xs-2 control-label">{{ resource["gve.common.attach"] }}</label> 
      <div class="col-xs-5"> 
       <ol class="marTop10"> 
        <li class="exactFit" ng-repeat="files in attachList">{{ files.fileName }}</li> 
       </ol> 
      </div> 
     </div> 



$scope.populateView = function() 
    { 
     $rootScope.inputSpin  = false; 
     $rootScope.modifiedCaseData = $scope.problem; 
     $scope.showReviewBtn  = $rootScope.showReviewBtn; 
     $scope.attachList = []; 

     $scope.attachList.push({fileId:"100",fileName:"Test.pdf"}); 
     for(i in $scope.attachList) { 
      console.log (i, $scope.attachList[i]); 
     } 
    }; 

文件名是沒有得到顯示HTML {{files.fileName}},即使{FILEID:「100」,文件名:「檢驗.pdf」}被添加到$ scope.attachList

編輯1:我很抱歉沒有提到這些細節。 ng-controller已被定義,並且populateView()從另一個函數中被調用。

編輯2:從console.log。

09:56:17.486 problemCtrl.js?gccm=1.0:185 0 Object {fileId: 100, fileName: "untitled 8.txt"}fileId: 100fileName: "untitled 8.txt" 
+0

我沒有看到NG-控制器或NG-應用。我希望這一部分已經涵蓋。除此之外,'$ scope.attachList'在'$ scope.populateView'函數內被賦值,但是我沒有看到它在任何地方被調用。 – sisyphus

+0

在函數內部調用'console.log',調用'populateView'後調用它來驗證設置的值。 – sisyphus

+0

嗨,這裏是從console.log 09:56:17.486 problemCtrl.js?gccm = 1.0:185 0對象{fileId:100,fileName:「untitled 8.txt」} fileId:100fileName:「untitled 8.txt 「....我不確定爲什麼雙向綁定不會發生在這種情況下 – Sheetal

回答

0

您是否缺少ng-controller指令或者它已在別處定義?

+0

其已定義 – Sheetal

+0

嘗試將ng-repeat移動到ol標籤並讓我知道.. –

+0

我試過了。它似乎沒有改變 – Sheetal

0

確保您呼叫的populateView()

DEMO

var app = angular.module('test',[]); 
 
app.controller('testCtrl',function($scope){ 
 
$scope.populateView = function() 
 
    { 
 
     $scope.attachList = []; $scope.attachList.push({fileId:"100",fileName:"Test.pdf"}); 
 
    }; 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div ng-app="test" ng-controller="testCtrl" ng-init="populateView()" class="col-xs-5"> 
 
     <ol class="marTop10"> 
 
     <li class="exactFit" ng-repeat="files in attachList">{{ files.fileName }}</li> 
 
     </ol> 
 
</div>