【发布时间】:2017-05-09 12:06:31
【问题描述】:
对不起,如果这听起来很愚蠢。
我遇到了类似于this question 的问题,虽然接受的答案有效,但它也带来了另一个问题:当我向数组添加新对象时,Angular 不会呈现它。
app.controller('MainCtrl', [
'$scope',
'$filter',
'posts',
function($scope, $filter, posts) {
$scope.posts = $filter('orderBy')(posts.posts, '-votes')
}
]
我的添加功能:
o.addPost = function(post) {
return $http.post('/posts', post).success(function(data) {
o.posts.push(data)
})
}
有什么我可以做的吗?
编辑:我要这样做:
o.addPost = function(post) {
return $http.post('/posts', post)
}
app.controller('MainCtrl', [
'$scope',
'$filter',
'posts',
function($scope, $filter, posts) {
$scope.posts = $filter('orderBy')(posts.posts, '-votes')
$scope.addPost = function() {
posts.addPost(param).then(function(response) {
$scope.posts.push(response.data)
})
}
]
【问题讨论】:
标签: javascript angularjs