Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 无法读取'';空的_Angularjs - Fatal编程技术网

Angularjs 无法读取'';空的

Angularjs 无法读取'';空的,angularjs,Angularjs,我正试着从一个情态杂志上发表一篇文章。我收到了这个错误消息 无法读取null的属性“CustomerPhoneNumber” 当我删除所选客户时,一切正常。ng模型的一部分。我需要让它按原样工作。不确定如何使其读取输入值 //Post New Customer $scope.submitCustomer = function () { var data = { CustomerId: $scope.selectedCustomer.CustomerId,

我正试着从一个情态杂志上发表一篇文章。我收到了这个错误消息

无法读取null的属性“CustomerPhoneNumber”

当我删除所选客户时,一切正常。ng模型的一部分。我需要让它按原样工作。不确定如何使其读取输入值

 //Post New Customer
$scope.submitCustomer = function () {
   var data = {
        CustomerId: $scope.selectedCustomer.CustomerId,
        CustomerPhoneNumber: $scope.selectedCustomer.CustomerPhoneNumber,
        CustomerName: $scope.selectedCustomer.CustomerName,
        CustomerFaxNumber: $scope.selectedCustomer.CustomerFaxNumber,
        CustomerAddress: $scope.selectedCustomer.CustomerAddress,
        CustomerCity: $scope.selectedCustomer.CustomerCity,
        CustomerState: $scope.selectedCustomer.CustomerState,
        CustomerZipcode: $scope.selectedCustomer.CustomerZipcode,
        CustomerWebsite: $scope.selectedCustomer.CustomerWebsite,
        CustomerOtherShit: $scope.selectedCustomer.CustomerOtherShit,
        CustomerHidden: $scope.selectedCustomer.CustomerHidden,
        CustomerPM: $scope.selectedCustomer.CustomerPM,
        CustomerAdmin: $scope.selectedCustomer.CustomerAdmin,
        CustomerAccountant: $scope.selectedCustomer.CustomerAccountant,
        CustomerSuperintendent: $scope.selectedCustomer.CustomerSuperintendent

    }
    $http.post('/api/apiCustomer/PostNewCustomer', data).success(function (data, status, headers) {
        console.log(data); window.top.location.reload();
    });

};

 <form ng-submit="submitCustomer()" enctype="multipart/form-data">

                        <tabset>
                            <tab heading="CustomerList">
                                <div class="col-xs-12" style="margin-top:5px">
                                    <div style="overflow: auto;height:200px" id="scrollAreaCustomers">
                                        <table class="table">
                                            <tr>
                                                <th style="font-weight: bold;">Name</th>
                                            </tr>
                                            <tr><input type="text" placeholder="New Customer" ng-model="selectedCustomer.CustomerName" ng-enter="data.static = true" /></tr>
                                            <tr ng-repeat="customer in customerArray | filter:searchCustomerName" class="pointer">
                                                <td ng-click="setSelectedCustomer(customer);data.static = true">{{customer.CustomerName}}</td>
                                            </tr>
                                        </table>
                                    </div>
                                </div><!--End col-xs-12-->

                            </tab><!--End CustomerList Tab-->
                            <tab heading="CustomerDetails" active="data.static">
                                <div class="col-xs-12" style="margin-top:5px">
                                    <div class="inline-fields">
                                        <label>Name:</label>
                                        <input style="width:150px;margin-left:19px" type="text" ng-model="selectedCustomer.CustomerName" />
                                        <label style="margin-left: 80px">Website:</label>
                                        <input style="width:150px" type="text" ng-model="selectedCustomer.CustomerWebsite" />
                                    </div>
                                    <div class="inline-fields">
                                        <label style="margin-left:1px;">Address:</label>
                                        <input style="width:180px" ng-model="selectedCustomer.CustomerAddress" type="text">
                                    </div>
                                    <div class="inline-fields">
                                        <label style="margin-left: 30px">City:</label>
                                        <input style="width:80px;" ng-model="selectedCustomer.CustomerCity" type="text">

                                        <label>State:</label>
                                        <input style="width:30px" ng-model="selectedCustomer.CustomerState" type="text">

                                        <label>Zipcode:</label>
                                        <input style="width:50px" ng-model="selectedCustomer.CustomerZipcode" type="text">
                                    </div>
                                    <div class="inline-fields">
                                        <label style="margin-left: 14px">Phone:</label>
                                        <input style="width:121px;" ng-model="selectedCustomer.CustomerPhoneNumber" type="text">

                                        <label>Fax:</label>
                                        <input style="width:115px" ng-model="selectedCustomer.CustomerFaxNumber" type="text">

                                    </div>

                                </div><!--End col-xs-12-->
                            </tab>

                            <tab heading="CustomerEmployees">
                                <div class="col-xs-12" style="margin-top:5px">
                                    <div class="inline-fields" style="">
                                        <label style="margin-left:49px">PM:</label>
                                        <input style="width:150px" ng-model="selectedCustomer.CustomerPM" type="text">
                                    </div>
                                    <div class="inline-fields" style="">
                                        <label style="margin-left:26px">Admin:</label>
                                        <input style="width:150px" ng-model="selectedCustomer.CustomerAdmin" type="text">
                                    </div>
                                    <div class="inline-fields" style="">
                                        <label style="margin-left:1px">Acountant:</label>
                                        <input style="width:150px" ng-model="selectedCustomer.CustomerAccountant" type="text">
                                    </div>
                                    <div class="inline-fields" style="">
                                        <label style="margin-left:30px">Super:</label>
                                        <input style="width:150px" ng-model="selectedCustomer.CustomerSuperintendent" type="text">
                                    </div>
                                </div>
                            </tab>
                        </tabset><!--End Tab Content-->
                        <div class="col-xs-12">
                            <input style="margin-left:360px;margin-top:25px;width:70px" type="submit" value="Save" go-click="#" />
                            <input style="margin-left: 20px; width: 70px; margin-top: 25px" type="button" data-dismiss="modal" value="Exit" go-click="#" />
                        </div>
                    </form>
//发布新客户
$scope.submitCustomer=函数(){
风险值数据={
CustomerId:$scope.selectedCustomer.CustomerId,
CustomerPhoneNumber:$scope.selectedCustomer.CustomerPhoneNumber,
CustomerName:$scope.selectedCustomer.CustomerName,
CustomerFaxNumber:$scope.selectedCustomer.CustomerFaxNumber,
CustomerAddress:$scope.selectedCustomer.CustomerAddress,
CustomerCity:$scope.selectedCustomer.CustomerCity,
CustomerState:$scope.selectedCustomer.CustomerState,
CustomerZipcode:$scope.selectedCustomer.CustomerZipcode,
CustomerWebsite:$scope.selectedCustomer.CustomerWebsite,
CustomerOtherShit:$scope.selectedCustomer.CustomerOtherShit,
CustomerHidden:$scope.selectedCustomer.CustomerHidden,
CustomerPM:$scope.selectedCustomer.CustomerPM,
CustomerAdmin:$scope.selectedCustomer.CustomerAdmin,
CustomerAccount:$scope.selectedCustomer.CustomerAccount,
CustomerSupervendent:$scope.selectedCustomer.CustomerSupervendent
}
$http.post('/api/apiCustomer/PostNewCustomer',data.).success(函数(数据、状态、标题){
console.log(数据);window.top.location.reload();
});
};
名称
{{customer.CustomerName}
姓名:
网站:
地址:
城市:
声明:
Zipcode:
电话:
传真:
下午:
管理员:
助理:
超级的:
更新

TypeError: Cannot read property 'CustomerId' of null
at Scope.$scope.submitCustomer (http://localhost:44301/MyScripts/JobController.js:255:48)
at http://localhost:44301/Scripts/angular.js:10836:21
at http://localhost:44301/Scripts/angular.js:19094:17
at Scope.$eval (http://localhost:44301/Scripts/angular.js:12673:28)
at Scope.$apply (http://localhost:44301/Scripts/angular.js:12771:23)
at HTMLFormElement.<anonymous> (http://localhost:44301/Scripts/angular.js:19093:21)
at HTMLFormElement.x.event.dispatch (http://localhost:44301/Scripts/jquery-1.10.2.min.js:22:14129)
at HTMLFormElement.v.handle (http://localhost:44301/Scripts/jquery-1.10.2.min.js:22:10873) angular.js:10061(anonymous function) angular.js:10061(anonymous function) angular.js:7357Scope.$apply angular.js:12773(anonymous function) angular.js:19093x.event.dispatch jquery-1.10.2.js:9789v.handle
TypeError:无法读取null的属性“CustomerId”
在范围内。$Scope.submitCustomer(http://localhost:44301/MyScripts/JobController.js:255:48)
在http://localhost:44301/Scripts/angular.js:10836:21
在http://localhost:44301/Scripts/angular.js:19094:17
在范围内。$eval(http://localhost:44301/Scripts/angular.js:12673:28)
在范围内。$apply(http://localhost:44301/Scripts/angular.js:12771:23)
在HTMLFormElement。(http://localhost:44301/Scripts/angular.js:19093:21)
在HTMLFormElement.x.event.dispatch(http://localhost:44301/Scripts/jquery-1.10.2.min.js:22:14129)
位于HTMLFormElement.v.handle(http://localhost:44301/Scripts/jquery-1.10.2.min.js:22:10873)angular.js:10061(匿名函数)angular.js:10061(匿名函数)angular.js:7357Scope.$apply angular.js:12773(匿名函数)angular.js:19093x.event.dispatch jquery-1.10.2.js:9789v.handle

好的,这是您的问题:

  $scope.customers = [
    {CustomerName: 'PizzaHut', CustomerAddress: '1234 Street', CustomerWebsite: 'website.com', CustomerCity: 'Houston', CustomerState: 'TX', CustomerZipcode: '77493',CustomerPhoneNumber: '713-987-5632', CustomerFaxNumber: '281-789-2145'}, 
    {CustomerName: 'PappaJohns', CustomerAddress: '9876 Hayes', CustomerWebsite: 'widget.com', CustomerCity: 'Katy', CustomerState: 'TX', CustomerZipcode: '77042',CustomerPhoneNumber: '281-452-8523', CustomerFaxNumber: '713-565-9657'}
    ];
  $scope.customerArray = [];
  $scope.selectedCustomer = $scope.customerArray[0];
您可以将客户添加到scope.customers和scope.customerArray,后者只是一个空数组

选择客户时,您选择的是空阵列的第一个成员

因此,改变这一点:

  $scope.selectedCustomer = $scope.customerArray[0];
为此:

  $scope.selectedCustomer = $scope.customers[0];
编辑

好的,我看到了你的更新,但是你仍然有大致相同的问题

  $scope.customerArray = [
    {CustomerName: 'PizzaHut', CustomerAddress: '1234 Street', CustomerWebsite: 'website.com', CustomerCity: 'Houston', CustomerState: 'TX', CustomerZipcode: '77493',CustomerPhoneNumber: '713-987-5632', CustomerFaxNumber: '281-789-2145'}, 
    {CustomerName: 'PappaJohns', CustomerAddress: '9876 Hayes', CustomerWebsite: 'widget.com', CustomerCity: 'Katy', CustomerState: 'TX', CustomerZipcode: '77042',CustomerPhoneNumber: '281-452-8523', CustomerFaxNumber: '713-565-9657'}
    ];
  $scope.customerArray = [];

使用数据初始化数组,然后将其重新初始化为空数组。您正在将selectedCustomer设置为空数组的第一个成员。删除第二行应该是金色的。

我建议将其放入JSFIDLE或plunkr中。如果你这样做,你很可能会得到快速的帮助。通常我会,但我不知道如何设置帖子来给出相同的错误。这是