使用AngularJS从动态生成的表及其行中计算值的方法如下:
<div ng-controller="MyController">
<table>
<tr>
<th>列1</th>
<th>列2</th>
<th>计算结果</th>
</tr>
<tr ng-repeat="item in data">
<td>{{ item.column1 }}</td>
<td>{{ item.column2 }}</td>
<td>{{ calculateValue(item.column1, item.column2) }}</td>
</tr>
</table>
</div>
angular.module('myApp', [])
.controller('MyController', function($scope) {
$scope.data = [
{ column1: 1, column2: 2 },
{ column1: 3, column2: 4 },
{ column1: 5, column2: 6 }
];
$scope.calculateValue = function(column1, column2) {
return column1 + column2;
};
});
通过以上步骤,你可以使用AngularJS从动态生成的表及其行中计算值。每当数据发生变化时,计算结果也会相应更新。
AngularJS Select(选项框)
AngularJS 可是使用数组或对象创建一个下拉列表选项。
使用ng-options创建选项框
在AngularJS 中我们可以使用ng-option指令来创建一个下拉列表,列表通过对象和数组循环输出
实例:
AngularJS ng-model 指令
ng-model 指令用于绑定应用程序数据到HTML 控制器(input,select,textarea)的值
ng-model指令
ng-model指令可以将输入域的值与AngularJS 创建的变量绑定。
实例: