2014-01-13 185 views

回答

1

簡而言之:您要求的$scope.myOpt範圍是祖先的範圍實際上包含myOpt

龍答:此代碼:

<body ng-controller="MainCtrl"> 
    ... 
    <tr ng-repeat="row in rows"> 
     <td ng-repeat="cell in row"> 
      <select ng-change="changeSelect();" ng-model="myOpt" ng-options="..."></select> 

創建下列範圍層次:

$rootScope 
    MainCtrl scope <- myOpt is read here 
     1st ng-repeat scope 
      2nd ng-repeat scope <- myOpt is set here 

據JS原型繼承祖先範圍不能看到變量。

對於你的情況我建議通過myOptchangeSelect()

<select ng-change="changeSelect(myOpt)" ng-model="myOpt" ng-options="..."></select> 

和:

$scope.changeSelect = function(x) { 
    console.log(x); // or whatever 
}; 
+0

很多很多的感謝! – fizikst