2017-05-26 32 views
0

我想動態更改使用Angular JS的下拉列表控件的選擇項,但它不會更改視圖。 我試過this one,但還沒有結果!AngularJS:動態更改下拉列表控件的選擇項使用

控制器:

$scope.dischargeType = {id:0,title:''}; 

$scope.setSelect = function() { 
    debugger; 
    $scope.dischargeType = $scope.dischargeTypes[1]; 
    alert($scope.dischargeType.title); 
    // it shows that the $scope.operationType get the value,but no changes on html 
} 

查看:

<label class="col-sm-3 control-label">Discharge Type</label> 
<div class="col-sm-9"> 
    <select ui-select2 data-ng-model="dischargeType" id="add-dischargeType" name="dischargeType"> 
    <option data-ng-repeat="item in dischargeTypes" value="{{item.id}}">{{item.title}}</option> 
    </select> 
</div> 

謝謝確實如此。

回答

0

從您發佈的代碼中看到......看起來您並沒有在代碼中調用setSelect函數。

所以基本上你有一個功能可以做某些事情,但是如果你永遠不會調用它,那麼它將不會實際執行。另外,您可能想要提及在查看頁面時是否在Chrome的控制檯窗口中收到錯誤。

+0

我已經刪除了調用函數的代碼。 Discover

+0

函數setSelect()使用html中的按鈕調用,並且警報正在提升並顯示我期望的值。在我的控制檯中沒有錯誤。 – Discover