Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question
 
Unless there is something you are not including in your question, this seems simple enough. What have you tried ? –  Simon Belanger Sep 21 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 –  SpookyMindz Sep 21 at 11:48
 
@SimonBelanger please check this question stackoverflow.com/questions/18932585/… –  SpookyMindz Sep 21 at 12:27
 
Do the object indoors and outdoors have some properties? –  Chandermani Sep 21 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 –  SpookyMindz Sep 22 at 11:33
add comment

2 Answers

up vote 1 down vote accepted

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

share|improve this answer
 
Thanks for your concern and provide such a simple and best example –  SpookyMindz Sep 22 at 11:37
 
its my pleasure –  Blu Angel Sep 22 at 11:37
add comment
$scope.update = function() {
};

Replace To:

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

See DEMO

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.