MongoDB에 데이터를 제출할 때 angular unshift 키워드가이 오류를 표시합니다. Angular에 대해 많이 알지 못합니다. 왜 이런 오류가 나옵니까?mongodb에 데이터를 제출할 때 각도 Unshift 오류
var app=angular.module('app',[]);
app.controller('PostsCtrl', function($scope, $http){
$http.get('/api/posts')
.then(function(response) {
$scope.posts = response.post;
alert(JSON.stringify(response));
});
$scope.addPost=function(){
if($scope.postBody){
$http.post('/api/posts',{
username:'Tahir',
body:$scope.postBody
}).then(function successCallback(response) {
$scope.posts.unshift(post)
$scope.postBody=null
alert(JSON.stringify(response));
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
})
}
}
}
시도 할 수있는 것은''undefined'입니다 $ scope.posts'는'undefined'이거나'$ scope.posts = []'와 같이 먼저 정의해야합니다 –