Abel Abel - 5 months ago 8
AngularJS Question

can not set drop down value on post success

I am new to angular and I am creating a edit page and I load data through success callback on post. But my dropdown values are not loaded while my text values are coming fine. All the recieving data are fine, I don't know why drop down values are not get set?

$http.post('article/get-article.php',{id: id})
.success(function(response){
$scope.article = response[0];
});

//My category drop down html
<select class="form-control" name="category" ng-model="article.category" ng-options ="art.id as art.title for art in categories" required >
</select>


EDIT
I am attaching my full controller code

myApp.controller('editArticle', ['$scope', '$http','$routeParams', 'editArt',function($scope,$http, $routeParams, editArt){
$scope.article = {};
$scope.statusList = [{title: 'New', id: 1, role: "Author"},{title: 'Approved', id: 2, role: "Admin"},{title: 'Rejected', id: 3, role: "Admin"}];
$scope.categories = [{title: 'Cricket',id: 1},{title: 'Football',id: 2 },{title: 'Tennis',id: 3},{title: 'Golf',id: 4,}];

var id = $routeParams.id;
article = "";
//$scope.article = editArt.getData('article/get-article.php',{id: id});
$http.post('article/get-article.php',{id: id})
.then(function(response){
$scope.article = response.data[0];
//$scope.article.category = response.data[0].category;
console.log(response.data);
});
}]);

Answer

@Deep Comment on check whether category is string or number is done the trick

$scope.article.status = parseInt(response.data[0].status);
$scope.article.category = parseInt(response.data[0].category);

Thank you all.