angular.js:13920 TypeError:无法读取属性' push'为null

时间:2016-09-16 12:04:03

标签: javascript angularjs

这个程序是用于将工厂的JSON数据发送到localhost,但我得到了错误。当选择订单时,订单将被发送到另一个订单。当我单击选择按钮时,控制台中发生错误。

主要HTML页面

Private Sub Paddline_Click()
Dim i As Long
    Dim rng3rows As Range
    Dim rng3CellsColumn As Range
    For i = Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
        If Range("A" & i).Value = "~P~" Then
            Set rng3rows = Range(Rows(i), Rows(i + 2))  'using a range to include the 3 rows you want to copy over
            rng3rows.Copy
            Rows(i).Insert
            Set rng3CellsColumn = Range(Cells(i, 1), Cells(i + 2, 1))  'using a range to clear the the cells in the column A
            rng3CellsColumn.ClearContents
            Rows(i).Select
        End If
    Next
    Application.CutCopyMode = False
    Set rng3rows = Nothing
    Set rng3CellsColumn = Nothing    
    'in randul 1
    Cells(ActiveCell.Row, 2).Value = Pclient.Value
    Cells(ActiveCell.Row, 3).Value = Pcodclient.Value
    Cells(ActiveCell.Row, 4).Value = ""
    Cells(ActiveCell.Row, 5).Value = Pnrcomanda.Value
    Cells(ActiveCell.Row, 7).Value = Pdesc1.Value
    Cells(ActiveCell.Row, 8).Value = Pperscontact.Value
    Cells(ActiveCell.Row, 28).Value = Pstatus.Value    
    'in randul 2
    Cells(ActiveCell.Row + 1, 2).Value = Pclient.Value
    Cells(ActiveCell.Row + 1, 4).Value = ""
    Cells(ActiveCell.Row + 1, 8).Value = Pdesc2.Value
    Cells(ActiveCell.Row + 1, 10).Value = Pdurata.Value
    Cells(ActiveCell.Row + 1, 11).Value = Pdatadelay.Value
    Cells(ActiveCell.Row + 1, 27).Value = Pusername.Value
    Cells(ActiveCell.Row + 1, 28).Value = Pstatus.Value    
    'in randul 3
    Cells(ActiveCell.Row + 2, 2).Value = Pclient.Value
    Cells(ActiveCell.Row + 2, 4).Value = ""
    Cells(ActiveCell.Row + 2, 8).Value = Pdesc3.Value
    Cells(ActiveCell.Row + 2, 10).Value = Pdurata.Value
    Cells(ActiveCell.Row + 2, 27).Value = PusernameV.Value    
MsgBox "Datele au fost introduse in tabel."
    ActiveWindow.ScrollRow = 56
    Unload Me

并且控制器意味着将列表从工厂发送到本地存储..

'使用严格的';

<div class="jumbotron">
  <h3>'Allo, 'Allo!</h3>
  <p class="lead">
    <img src="images/yeoman.png" alt="I'm Yeoman"><br>
   Welcome to AMPATH Dev Meal System.
  </p>
  <p><a class="btn btn-lg btn-success" ng-href="#/">Splendid!<span class="glyphicon glyphicon-ok"></span></a></p>
</div>

<div class="row marketing">

    <h3>Select The Restaurant of your Choice</h3>
        <!--<form name="menuForm"-->
            <!--Displaying restnames in lists-->
<form>
    <h2>Restaurants</h2>
    <ul> <h3>
        <li ng-repeat="(key,Cafeteria) in myRestaurant">
            {{Cafeteria.restname}} 
        <div>
        <button class="btn btn-lg btn-success" ng-submit="order" ng-click="orderfood(key,Cafeteria)">Check foods</button> 
        </div>
        </li>
        </h3>
    </ul>
</form>
</div>
<div>
 <table border="1" class="w3-table w3-striped w3-bordered w3-border">
     {{me}}
        <thead>
            <tr>
                <td>Food Name</td>
                <td>Price</td>
                <td>Select your order</td>
            </tr>
        </thead>

        <tbody>
            <tr ng-repeat="food in foods">
                <td>{{food.foodname}}</td>
                <td>{{food.price | currency}}</td>
                <td><button class="w3-btn w3-ripple" value="Show alert" ng-click="storage(food)">&#4598; Select</button></td>
            </tr>
        </tbody>
    </table>
</div>

我很感激你的回答

2 个答案:

答案 0 :(得分:0)

似乎JSON.parse($window.localStorage.getItem("orderedfoods"))返回的内容不是数组。也许本地存储中没有任何东西?当您在localstorage中处理不存在的项时,它将返回null。 您可以尝试修复它:

var orderedfood = JSON.parse($window.localStorage.getItem("orderedfoods"))||[];

答案 1 :(得分:0)

您的orderedfood数组对象为空。您可以取消注释控制台日志并确认。为避免该错误,您可能需要检查null并为orderedfood分配一个空数组,如下所示:

 var orderedfood = JSON.parse($window.localStorage.getItem("orderedfoods"));
 console.log(orderedfood);
orderedfood = orderedfood || [];