我是Node JS和MAEN堆栈的新手,我正在关注MEANJS的教程以学习它,在此截屏视频http://www.youtube.com/watch?v=HNpMCFB8TFI&list=PL6rhBJX0L3TWYrwrQIi1_MzQDvVhkUVPI&index=26中,我们可以创建新客户。但是,我无法创建新客户,因为我收到一条错误消息,提示“对象不是函数”,这是指Google chrome控制台建议的这一行“ var customer = new Customers”。这是代码

customersApp.controller('CustomersCreateController', ['$scope', '$stateParams', '$location', 'Authentication', 'Customers',
    function($scope, Customers ) {
            // Create new Customer
            this.create = function() {
                    // Create new Customer object
                    var customer = new Customers ({
                            firstName: this.firstName,
                            surname: this.surname,
                            suburb: this.suburb,
                            country: this.country,
                            industry: this.industry,
                            email: this.email,
                            referred: this.referred,
                            phone: this.phone,
                            channel: this.channel
                    });

                    // Redirect after save
                    customer.$save(function(response) {
                            // Clear form fields
                            $scope.firstName = '';
                            $scope.surname = '';
                            $scope.suburb = '';
                            $scope.country = '';
                            $scope.industry = '';
                            $scope.email = '';
                            $scope.referred = '';
                            $scope.phone = '';
                            $scope.channel = '';

                    }, function(errorResponse) {
                            $scope.error = errorResponse.data.message;
                    });
            };
    }


]);

请注意,更新控制器中的更新功能可以正常工作,这是代码。

customersApp.controller('CustomersUpdateController', ['$scope', '$stateParams', '$location', 'Authentication', 'Customers',
function($scope, Customers ) {
    // Update existing Customer
    this.update = function(updatedCustomer) {
        var customer = updatedCustomer;

        customer.$update(function() {
        //wont do anything as the modal will be closed
        }, function(errorResponse) {
            $scope.error = errorResponse.data.message;
        });
    };
}


]);

我真的很感谢您的帮助,在此先感谢

最佳答案

在依赖项列表中,您传入了$ stateParams,$ location和Authentication(可能不需要)。

CustomersApp.controller('CustomersCreateController', ['$scope', '$stateParams', '$location', 'Authentication', 'Customers',
    function($scope, Customers ) {


无论如何,您在dependencies数组中指定的顺序就是将它们传递到控制器中的顺序。因此,在您的控制器中,“ $ scope”是指$ scope,而“ Customers”是指$ stateParams。

您可能可以将其更改为如下所示:

CustomersApp.controller('CustomersCreateController', ['$scope', 'Customers',
    function($scope, Customers ) {


或者,如果您需要这些服务:

CustomersApp.controller('CustomersCreateController', ['$scope', '$stateParams', '$location', 'Authentication', 'Customers',
    function($scope, $stateParams, $location, Authentication, Customers ) {

08-15 14:29