gpt4 book ai didi

html - 如何在angularJS中将数据放入数组?

转载 作者:行者123 更新时间:2023-11-28 00:38:47 25 4
gpt4 key购买 nike

我在这里分享了 plunker 链接。请让我知道我做错了什么?

<a href="https://plnkr.co/edit/3VryaPGtgPRD6Nn8zx7v">Plunker link is here</a>

最佳答案

看看这个

var app = angular.module('app', []);
app.controller('appController', function ($scope, $http) {
$scope.Items = [
{'id':1,'name':'Apple','price':100,'qty':1},
{'id':2,'name':'Coconut','price':20,'qty':1}
];
$scope.proceed = function(){
data=$scope.Items;
alert(data);
};
});

HTML代码:

<!DOCTYPE html>
<html ng-app="app" ng-controller='appController'>

<head>
<link rel="stylesheet" href="style.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<script src="script.js"></script>
</head>

<body>
<form >
<table border="1">
<tr>
<td>Id</td>
<td>Name</td>
<td>Price</td>
<td>QTY</td>
<td>Data</td>
</tr>
<tr ng-repeat='Item in Items'>
<td>{{Item.id}}</td>
<td>{{Item.name}}</td>
<td>{{Item.price}}</td>
<td>{{Item.qty}}</td>
<td><input type="text" ng-init="{{Item.SubTotal = Item.price * Item.qty}}" name="Item.SubTotal" ng-model="Item.SubTotal" /></td>
</tr>
</table><br>
<input type="submit" ng-click="proceed()" />
</form>
</body>

</html>

关于html - 如何在angularJS中将数据放入数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53984901/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com