我在使用離子框架時遇到了一些問題。我正在嘗試在雜貨應用上工作,用戶可以在其中添加項目。我寫的代碼無法顯示空白字段「未定義」,但當我用「div」標籤替換「ion-content」標籤時,我的代碼工作正常。我很困惑爲什麼會發生這種情況?請幫忙謝謝。離子內容不允許推送對象。 Showing undefined
<ion-content>
<div class="grocery-wrapper">
<ion-item ng-repeat="groceryItem in groceryItems">
<div class="row">
<div class="col col-20">
<label class="checkbox checkbox-balanced">
<input class="checkbox" type="checkbox"/>
</label>
</div>
<div class="col col-33 g-items">{{groceryItem.itemName}}</div>
<div class="col g-items">{{groceryItem.Quantity}}</div>
<div class="col g-items">{{groceryItem.Rate}} rs/kg</div>
</div>
</ion-item>
<div id="getGroceryItem" ng-show="GroceryItem">
<div class="row">
<div class="col col-50">
<label class="item item-input item-floating-label">
<span class="input-label">Grocery Item</span>
<input ng-model="gItem" type="text" placeholder="Grocery Item">
</label>
</div>
<div class="col">
<label class="item item-input item-floating-label">
<span class="input-label">Kg</span>
<input ng-model="gKg" type="text" placeholder="kg">
</label>
</div>
<div class="col">
<label class="item item-input item-floating-label">
<span class="input-label">Price</span>
<input ng-model="gPrice" type="text" placeholder="Price">
</label>
</div>
</div>
<div class="row">
<button class="button button-block button-balanced button-medium" ng-click="addGroceryItem()">
ADD ITEM
</button>
</div>
</div>
</div>
</ion-content>
app.controller('getGrocery', function($scope){
//console.log("Grocery Items");
$scope.groceryItems = [
{
'itemName':'Rice',
'Quantity':'5kg',
'Rate':'50'
},
{
'itemName':'Wheat',
'Quantity':'6kg',
'Rate':'44'
}
];
//Hide show elemment
$scope.GroceryItem = false;
$scope.addGroceryItem = function() {
//$scope.groceryObj = {};
$scope.groceryItems.push(
{
itemName:$scope.gItem,
Quantity:$scope.gKg,
Rate:$scope.gPrice
}
);
console.log($scope.gItem)
console.log($scope.gKg)
console.log($scope.gPrice)
$scope.gItem = "";
$scope.gKg = "";
$scope.gPrice = "";
}
})
http://i.stack.imgur.com/1at2T.png