【发布时间】:2017-08-22 02:35:35
【问题描述】:
看到这个plunker
在 jQuery 中,我可以获取其 td 的文本并将其置于警报中,但如何在 Angular 中实现呢?我应该将其设为原生 javascript 吗?
这是脚本
var app = angular.module('plunker',[]);
app.controller('ctrl',function($scope){
$scope.edit = function(){
alert("ID = " + $scope.id + "\n NAME = " + $scope.name);
};
$scope.items = [
{id:"1",name:"name 1"},
{id:"2",name:"name 2"},
{id:"3",name:"name 3"}
];
});
HTML
<body ng-controller="ctrl" ng-app="plunker">
<table>
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>edit</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="x in items">
<td ng-model="x.id">{{x.id}}</td>
<td>{{x.name}}</td>
<td><button ng-click="edit()">edit</button></td>
</tr>
</tbody>
</table>
</body>
附言
ng-repeat 是动态的,我怎样才能获得它的价值?
【问题讨论】:
-
为什么不
edit(x.id)或edit(x)?
标签: javascript angularjs