0
當我嘗試輸入隨機數據爲通過.push方法它不是在這裏工作 數組或JSON文件.push方法是我的代碼 陣列碼是角JS的JSON文件無法正常工作
$scope.stock =[{
"name":"Pepsi",
"price":65,
"color":"black",
"avaliable":true}]
嘗試通過NG-模型結合
<form ng-submit="addItem()">
<input type="text" placeholder="Name" ng-model="newName" />
<input type="text" placeholder="Price" ng-model="newPrice" />
<input type="text" placeholder="color" ng-model="newcolor" />
<input class="submit" type="submit" value="Add New Item" />
</form>
JS代碼是
$scope.addItem = function(){
$scope.stock.push({
name: $scope.newName,
price: parseInt($scope.newPrice),
color: $scope.newcolor,
avaliable: true
});
你得到任何錯誤?我認爲你的代碼看起來不錯 –
你初始化了$ scope.stock = []; – Vivz
沒有給我任何東西? –