简体   繁体   English

AngularJS:使用以下命令动态更改下拉列表控件的选择项

[英]AngularJS: Dynamically change select item of a dropdown list control using

I want to dynamically change select item of a dropdown list control using Angular JS, but it does not change the view. 我想使用Angular JS动态更改下拉列表控件的选择项,但它不会更改视图。 I tried this one but no result yet! 我尝试了这个,但没有结果!

Controller: 控制器:

$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
}

View: 视图:

<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>

Thank you indeed. 的确谢谢你。

From the code you posted... It doesn't look like you're actually calling the setSelect function in your code. 从您发布的代码中...看起来您实际上并不是在代码中调用setSelect函数。

So basically you have a function made to do something, but if you never call it, it won't actually execute. 因此,基本上,您具有做某事的功能,但是如果您从不调用它,它将实际上不会执行。 Also, you may want to mention whether or not you're getting errors in the console window of chrome when you're viewing the page. 另外,您可能想提及在查看页面时,是否在chrome的控制台窗口中出现错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM