Excuse me if this comes across as silly.
I'm encountering a problem that is reminiscent of this question. While the accepted solution worked, it brought up another issue: Angular doesn't render a new object added to the array.
app.controller('MainCtrl', [
'$scope',
'$filter',
'posts',
function($scope, $filter, posts) {
$scope.posts = $filter('orderBy')(posts.posts, '-votes')
}
]
This is my add function:
o.addPost = function(post) {
return $http.post('/posts', post).success(function(data) {
o.posts.push(data)
})
}
Is there anything I can do to address this?
UPDATE: Here's what I've decided on:
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)
})
}
]