I started using angularjs in a project. Here i have a quest. I have the below HTML
<div>
<label for="lastname">Bank Name :</label>
<select ui-select2 ng-model="bank.id">
<option></option>
<option ng-repeat="bank in banks" value="{{bank.id}}">{{bank.text}}</option>
</select>
</div>
I iterate all the banks to the dropdown. User selects and press SAVE. I correctly got the id and save it to the DB. When the user comes back i could not set the value of the drop down to the one he selected. I do this in the controller.js
$http.get('/AdServerLongTail/api/user').
success(function(data, status, headers, config) {
if(status == 200){
$scope.id = (data["id"]);// user id
$scope.bank.id = (data["bankId"]);
}
}).
error(function(data, status, headers, config) {
alert("fail");
});
How can I set it to bankID 11 letssay, which is XX Bank?
You should NOT use ng-repeat in this way. Please look at ngOptions http://docs.angularjs.org/api/ng.directive:select
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With