Javascript AngularJs TypeError:$scope.posts.push不是函数
当我用angularJs向api发布一个细节时,我得到了一个类似于Javascript AngularJs TypeError:$scope.posts.push不是函数,javascript,html,angularjs,Javascript,Html,Angularjs,当我用angularJs向api发布一个细节时,我得到了一个类似于TypeError:$scope.posts.push的错误:$scope.posts.push不是一个函数现在我如何修复它? 我的邮政编码是: AdminApp.controller('AddVehicleModalCtrl', ['$scope', '$rootScope', '$modalInstance','$http','toaster', function ($scope, $rootScope, $modalIns
TypeError:$scope.posts.push的错误:$scope.posts.push不是一个函数
现在我如何修复它?
我的邮政编码是:
AdminApp.controller('AddVehicleModalCtrl', ['$scope', '$rootScope', '$modalInstance','$http','toaster', function ($scope, $rootScope, $modalInstance,$http,toaster) {
$scope.create = function(){
$http.post(AppCore.getGlobalApiUrl()+'vehicle_type', {"vehicle_type": $scope.post.vehicle_type})
.success(function(response, status, headers, config){
$modalInstance.dismiss('cancel');
toaster.pop('success', "post", "done");
$scope.posts.push(response.posts);
$scope.$apply();
})
.error(function(response, status, headers, config){
$scope.error_message = response.error_message;
});
};
$scope.cancel = function () {
$scope.post = "";
$modalInstance.dismiss('cancel');
};
}]);
您尚未将
$scope.posts
定义为数组。在您的$scope.create
定义上方,只需插入一个初始化语句,如
$scope.posts = [];