I try to get data in api and I get object in console.log like this :
Object {_id: "590c14b1bf38e524e4b1a1ca", name: "John", age: 22, __v: 0}
Here is my code I use to get it and display .
server
detailRoute.route('/detail/:name')
.get(function(req,res) {
User.findOne({name:req.params.name},function(err,user) {
console.log(user);
if (err){
res.status(404).send(err);
}else{
res.status(200).json(user);
}
})
});
js:
var vm = this;
vm.dt =[];
vm.getDetail = function() {
$http.get('/api/detail/' + $stateParams.dt , $stateParams.dt)
.then(function(response) {
vm.dt = response.data;
console.log(response.data);
});
};
vm.getDetail();
html:
<ul ng-repeat="d in vm.dt">
<li></li>
<li></li>
</ul>
And nothing display . I try change to
vm.dt.push(response.data)
And it worked . So I want ask why my code above not work . Thank for any help
via Thanh Tùng
No comments:
Post a Comment