Upon loading the page, the dropdown menu is populated with various values (such as 1, 2...7). However, when attempting to set a specific value based on a certain condition within a promise, it doesn't seem to work. How can this issue be resolved?
html:
<div ng-app="app" ng-controller="Ctrl">
<select id="ddlSets" data-ng-model="SetId">
<option value="0">-- Select Set --</option>
<option data-ng-repeat="item in Sets" value="{{item.Id}}">{{item.Code}}</option>
</select>
</div>
ctrl.js:
var app = angular.module("app",[]);
app.controller("ctrl",["$scope","Factory",function($scope,Factory){
var init = function(){
//$scope.Sets = (code here to bind data to the dropdown)
var promise = Factory.GetSetId();
promise.then(function (success) {
if (success.data == 5) {
$scope.SetId = 5; //The value remains unset despite attempts.
}
},
function (error) {
console.log(error);
});
}
//It works if set here - $scope.SetId = 7;
init();
}]);
factory.js:
app.factory("Factory", ["$http",function ($http) {
var factory = {};
factory.GetSetId = function () {
return $http({
url: "http://localhost:12345.asmx/GetSetId",
method: "GET"
}).success(function (data, status) {
}).error(function (data, status) {
});
}
return factory;
}]);