【问题标题】:Updating dropdown list with AngularJS使用 AngularJS 更新下拉列表
【发布时间】:2016-04-12 22:18:34
【问题描述】:

我希望有机会从下拉列表中选择一个值并单击链接以获取下拉列表的下一个值。如果我单击链接,如何从下拉列表中更新选定的值?

<select class="dropdown-select" name="mySelect" id="chapter" ng-options="option.Icnumber for option in selected" 
ng-model="selected.Icnumber" ng-change="updateChapter(selected.Icnumber.Icnumber)">
</select>

<a ng-show="nextChapter" class="ng-hide" ng-click="updateChapterNext(selected.Icnumber.Icnumber)">Next Chapter</a>

谢谢!

【问题讨论】:

    标签: javascript angularjs drop-down-menu controller


    【解决方案1】:

    Angular 有一个叫做双向绑定的特性,无论你在 $scope 中拥有什么并在模板中使用它,当你更新控制器中的值时,它会自动更新模板中的值。

    对于您的问题,您使用selected 作为下拉值。

    所以在您的updateChapterNext 函数中修改selected 的值

    所以

    $scope.updateChapterNext = function(param){
      // do your thing to call next chapter
      // and assign the response or new value to selected
      $scope.selected = newValueForSelected;
    }
    

    这将更新下拉列表中的选定值

    【讨论】:

      猜你喜欢
      • 2018-01-17
      • 2019-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多