【问题标题】:AngularJS: Dynamically change select item of a dropdown list control usingAngularJS:使用动态更改下拉列表控件的选择项
【发布时间】:2017-05-27 01:57:24
【问题描述】:

我想使用 Angular JS 动态更改下拉列表控件的选择项,但它不会更改视图。 我试过this one,但还没有结果!

控制器:

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

真的谢谢你。

【问题讨论】:

    标签: javascript angularjs


    【解决方案1】:

    根据您发布的代码...看起来您实际上并未在代码中调用setSelect 函数。

    所以基本上你有一个函数来做某事,但如果你从不调用它,它实际上不会执行。此外,您可能想提及在查看页面时是否在 chrome 的控制台窗口中出现错误。

    【讨论】:

    • 我已经删除了调用该函数的代码。
    • 使用 html 中的按钮调用 setSelect() 函数,警报正在提高并显示我预期的值。我的控制台中也没有错误。
    猜你喜欢
    • 1970-01-01
    • 2015-09-07
    • 2011-08-02
    • 2020-07-10
    • 1970-01-01
    • 1970-01-01
    • 2019-06-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多