2017-08-21 161 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>