1

i want to change the dropdown options dynamically on click of button

HTML Code

 <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

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

5
  • Unless there is something you are not including in your question, this seems simple enough. What have you tried ? Commented Sep 21, 2013 at 11:44
  • i want to change data in dropdown when say. some botton click event what i have to do in that click event of button to replace data to the new one i have tow datas one in indoors that already bind and other is outdoors that i want to replace on click event i am new in angular-js Commented Sep 21, 2013 at 11:48
  • @SimonBelanger please check this question stackoverflow.com/questions/18932585/… Commented Sep 21, 2013 at 12:27
  • Do the object indoors and outdoors have some properties? Commented Sep 21, 2013 at 14:15
  • @Chandermani my indoor and outdoor objects are like below var outdoors = {}; outdoors.cast = [{ value: "00", text: "OutDoor" }]; var indoors = {}; indoors.cast = [ { value: "11", text: "InDoor" }]; yes Commented Sep 22, 2013 at 11:33

2 Answers 2

1
$scope.update = function() {
};

Replace To:

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

See DEMO

Sign up to request clarification or add additional context in comments.

Comments

0

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 = outdoorsin it

I create simple example for this you should check this out Thanks

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.