未捕获的TypeError:无法读取未定义的属性“companyName”

时间:2017-03-06 11:16:26

标签: javascript angularjs

我试图解决这个错误,但是因为我刚接触到angularjs而陷入困境并需要帮助解决这个问题:

$scope.companyModify = function(company) {
    var param = {
        companyName: $scope.companyName,
        billColumn: $scope.billColumn,
        billTitle: $scope.billTitle,
        serviceTax = $scope.serviceTax,
        wishMessage = $scope.wishMessage,
        billTypeId = $scope.billTypeId
    };

    SocketService.post(apiManage.apiList['CompanyModify'].api, param).then(function(resp) {
        var data = resp.data.response;

        if (data.status === true) {
            angular.forEach($scope.companyList, function(value) {
                if (value.billTypeId == billTypeId) {
                    value.$edit = false;
                }
            });

            Notify.alert(data.message, {
                status: 'success',
                pos: 'top-right',
                timeout: 5000
            });
            $scope.load();

        } else {
            Notify.alert(data.message, {
                status: 'danger',
                pos: 'top-right',
                timeout: 5000
            });
        }
    });
};
{{1}}

1 个答案:

答案 0 :(得分:0)

我认为你的对象' param'错误地构建了。

你可以试试 -

var param = {
    companyName: $scope.companyName,
    billColumn: $scope.billColumn,
    billTitle: $scope.billTitle,
    serviceTax: $scope.serviceTax,
    wishMessage: $scope.wishMessage,
    billTypeId: $scope.billTypeId
};

有' ='标志应由':'

替换

其次,在调用方法之前,请确保所有变量,companyName,billColumn等都附加到模型,即$ scope - $ scope.companyModify()

如果有帮助,请告诉我。