Angularjs or angularjs stuff store multiple dropdown data for selection in webservice
I am using Angular stuff and I am stuck with the multi selection dropdown where I selected multiple options and on ng-change. I call a function that will get the ID of each option and I will compare the API ID, but When I select it will provide data in a function of type When the first option is selected 123456 In the second option is selected 123456,456231
In choosing the third option 123456,456231,471258
so whenever I do a comparison it only enters the state once and no more, even I tried to break. It gives an error and does nothing.
<md-select ng-model="$parent.follower" placeholder="Select Person" multiple="true" ng-change="getFollowers(follower)">
<md-option ng-repeat="follower in followers" value="{{follower.id}}"> {{follower.full_name}}</md-option>
</md-select>
So let me know how to handle this situation if anyone has experience and is very good at it. Please let me know.
Thank you Shivam
source to share
I created a Codepen for you, where you can see the value changes every time Since I don't know the data format, I used the demo
Html
<div ng-controller="AppCtrl as ctrl" class="md-padding selectdemoBasicUsage" ng-app="MyApp">
<div>
<h1 class="md-title">Enter an address</h1>
<div layout="row">
<md-input-container>
<label>Street Name</label>
<input type="text">
</md-input-container>
<md-input-container>
<label>City</label>
<input type="text">
</md-input-container>
<md-select placeholder="State" ng-model="ctrl.userState" multiple="true" ng-change='changeValue(ctrl.userState)'>
<md-option ng-repeat="state in ctrl.states" value="{{state.abbrev}}">{{state.abbrev}}</md-option>
</md-select>
</div>
</div>
</div>
Angular code
'use strict';
angular
.module('MyApp')
.controller('AppCtrl', function($scope,$http) {
this.userState = '';
this.states = ('AL AK AZ AR CA CO CT DE FL GA HI ID IL IN IA KS KY LA ME MD MA MI MN MS ' +
'MO MT NE NV NH NJ NM NY NC ND OH OK OR PA RI SC SD TN TX UT VT VA WA WV WI ' +
'WY').split(' ').map(function (state) { return { abbrev: state }; });
$scope.changeValue=function(value){
console.log(value);
$http.post(//url).then(function(response){
//handle response here
});
}
});
Codepen for working solution http://codepen.io/anon/pen/WvygLZ
source to share