简体   繁体   English

在Angular JS中单击按钮上的更改下拉菜单选项

[英]Change Dropdown option on Button Click in Angular JS

i want to change the dropdown options dynamically on click of button 我想在单击按钮时动态更改下拉选项

HTML Code HTML代码

 <ul data-role="listview" data-inset="true">
     <li ng-controller="exerciseTypeCtrl">
          <select id="exerciseType" data-role="listview" ng-options="type as type.text for type in types.cast " ng-model="item" ng-change="update()">
          </select>
    </li>
 </ul>

Using This JS 使用这个JS

var myApp = angular.module('myApp',[]);

myApp.controller('exerciseTypeCtrl',function($scope,indoors,outdoors)
{
    $scope.types = indoors;
    $scope.update = function() {
    }
});

By Default I bind data indoors and I want to bind outdoors data on ng-click event so drop down updates dynamically I need Help on this issue 默认情况下,我在indoors绑定数据,并且我想在ng-click事件上绑定outdoors数据,因此动态下拉更新我需要有关此问题的帮助

$scope.update = function() {
};

Replace To: 替换为:

$scope.update = function() {
    $scope.types = outdoors;
}

See DEMO 演示

For this you should make button under the same ng-controller scope in which you defined select component and then on ng-click event of that button you call function which you will create in same controller like your update function and in that function you will assign new values like $scope.types = outdoors in it 为此,您应在定义select组件的ng-controller范围内创建button ,然后在该button ng-click事件中调用function ,该function将在同一控制器中创建,如update function并在该函数中分配新值,例如$scope.types = outdoors

I create simple example for this you should check this out Thanks 我为此创建了一个简单的示例 ,您应该检查一下

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

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