HTML:
<div class="container">
<div class="row">
<div class="col-md-9">
<h1>Update User Information</h1>
<div data-ng-controller="user">
<div data-ng-controller="userInfo">
<user-details user="users" user-filter="Single"></user-details>
<user-details user="users" user-filter="Married"></user-details>
</div>
</div>
</div>
</div>
</div>
**CONTROLLER + DIRECTIVE:**
.directive('userDetails', function () {
return {
restrict: 'E',
scope: {
users: '=',
userFilter: '@'
},
controller: function ($scope) {
$scope.showEdit = function () {
$scope.isEdit = true;
}
},
template: `<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Relation</th>
<th>Percentage</th>
<th></th>
</tr>
</thead>
<tbody>
<tr data-ng-repeat="user in users | filter: user.personalInfo.martialStatus= userFilter">
<td>{{user.personalInfo.firstName}} {{user.personalInfo.lastName}}</td>
<td>{{user.userRelations.relationshipType}}</td>
<td><span ng-if="!isEdit">{{user.personalInfo.percent}}</span><input type="text"
ng-if="isEdit" ng-model="user.personalInfo.percent" class="form-control"></td>
<td><a ng-click="showEdit()" href="#edit-user?index={{users.indexOf(user)}}">Update</a></td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="2">Total Percentage</td>
<td>100%</td>
<td><a ng-if="!isEdit" ng-click="showEdit()" href="#">Update</a><a ng-if="isEdit" ng-click="showEdit()" href="#">Save Percentage</a></td>
</tr>
</tfoot>
</table>
</div>`
};
})
重定向新页面HTML:
<div class="container">
<div class="row">
<div class="col-md-9">
<h1>EDIT User Information</h1>
<div data-ng-controller="user">
<div data-ng-controller="userInfo">
<input type="text" name="firstName" id="firstName" data-ng-model="matt"/>
</div>
</div>
</div>
</div>
</div>
帮助/指导 - 如何从URL到下一页检索ARRAY索引以显示要编辑的数据?
在重定向页面时,我能够传递正确的索引,如“#edit-user?index = 1”,但要迭代获取下一页的索引号或需要做控制器? 提前谢谢......