2014-09-10 2 views
0

Я пытаюсь сделать сообщение из модального. Я получаю сообщение об ошибкеНе могу прочитать свойство '' of null

Не удается прочитать свойство «CustomerPhoneNumber» нулевых

все отлично работает, когда я удалить selectedCustomer. часть 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> 

Обновленный

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 
+0

Я рекомендую поместить это в jsfiddle или plunkr. У вас гораздо больше шансов получить быструю помощь, если вы это сделаете. –

+0

обычно я бы, но я не уверен, как установить POST, чтобы дать ту же ошибку. Вот вопрос из предыдущего вопроса, с которым я имел помощь. Это то, что я использую сейчас. http://plnkr.co/edit/9SkOWYEQt5dAGPwKbEOW?p=preview – texas697

+0

В вашем плунтере есть случаи, которые смешивают «customerName» с «CustomerName», но это не приведет к ошибке, которую вы получаете. Сообщение также не является причиной этой ошибки, поскольку строка сообщения не ссылается на CustomerPhoneNumber. Вам нужно разместить больше информации (опять же, я рекомендую подходящий плункер), если вы хотите получить точную помощь. –

ответ

1

Хорошо, вот ваша проблема:

$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 = []; 

Вы инициализируете массив данными и затем повторно инициализируете его как пустой массив. Вы устанавливаете свой выбранный клиент для первого члена пустого массива. Удалите вторую строку, и вы должны быть золотыми.

+0

По моей вине я не менял клиентов на customerArray. вот как у меня это в моем проекте http://plnkr.co/edit/MdDIDXO9YRaDEBstU3A8?p=preview – texas697

+0

обновил мой ответ. –

+0

см. Обновленный. еще ошибка – texas697

Смежные вопросы