使用AngularJS grag$在ng中的第一个项目重复,并使用它在页面上以其他形式打开项目信息
Using AngularJS grag $first item in ng-repeat and use it to open items information in other form on page
我的用户将登录我的联系人页面,在该页面顶部以ng重复方式列出所有联系人的列表,然后可以添加和编辑联系人信息。列表中填充了一个编辑按钮,用于获取要编辑的各个联系人。
我的最新要求是获取列表中的第一个联系人,并将信息填充到表单中进行编辑,就好像用户单击了第一个编辑按钮一样。我想在ng重复中以某种方式使用$first,但如何在着陆时启动第一个联系人编辑对我来说是一个挑战
我读到过,每次消化发生时,$scope散列都会在内部循环,并根据以前的值进行脏检查。尝试使用init,但未读取;可能是我对Angular的生理学缺乏了解。
我希望在UI中完成这一切,但如果这是错误的,我在这个条目的底部包含了api调用。
table class="table table-hover table-striped table-condensed">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Title</th>
<th>Active</th>
<th></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="scacContact in searchScacContactResults">
<td>{{scacContact.contactFirstName}}</td>
<td>{{scacContact.contactLastName}}</td>
<td>{{scacContact.contactTitle}}</td>
<td>{{scacContact.activeDescription}}</td>
<td>
<button class="btn btn-primary btn-xs" ng-click="onEditScacContact(scacContact)" ng-disabled="isAdding||isEditing">Edit</button>
</td>
</tr>
</tbody>
</table>
<fieldset>
<legend>Add/Edit Contact</legend>
<form class="form-inline" role="form" name="AddEditContact">
<div class="col-md-8">
<div class="form-group"
<label class="col-lg-2 control-label">First Name</label>
<div class="col-lg-5">
<input class="form-control" id="ContactFirstName" name="ContactFirstName" type="text" placeholder="First Name" ng-disabled="!isAdding&&!isEditing" ng-model="scacContactDetails.contactFirstName" >
</div>
</div>
<div class="form-group"
<label class="col-lg-2 control-label" >Last Name</label>
<div class="col-lg-5">
<input class="form-control" id="ContactLastName" name="ContactLastName" type="text" placeholder="Last Name" ng-disabled="!isAdding&&!isEditing" ng-model="scacContactDetails.contactLastName" >
</div>
</div>
</div>
<div class="col-md-4">
<label class="control-label col-md-3">Active?</label>
<div class="col-lg-4">
<table class="table table-striped table-hover table-condensed fixed-element">
<thead>
<tr>
<th>Yes</th>
<th>No</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input name="rbActive" type="radio" ng-disabled="!isAdding&&!isEditing" ng-value="true" ng-model="scacContactDetails.active">
</td>
<td>
<input name="rbActive" type="radio" ng-disabled="!isAdding&&!isEditing" ng-value="false" ng-model="scacContactDetails.active">
</td>
</tr>
</tbody>
</table>
</div>
</div>
</form>
</fieldset>
//Getting list of Contacts per ScacID
var scacContactListRes = $resource("api/SearchScacContact");
scacContactListRes.query({ scacID: $scope.scacID }, function (scacContactList) {
$scope.searchScacContactResults = scacContactList;
});
一个解决方案是这个
<form class="form-inline" role="form" name="AddEditContact" ng-init="scacContactDetails = searchScacContactResults[0]>
感谢@sherwaniusman的引导,将数组中的第一个项目指向模型。我尝试了所有让UI调用ctlr中方法的方法,但都没有成功。可能是UI路由器的问题,但我最终只是在ctlr中调用了onEditScacContact();在查询内部,我在其中填充联系人的视图模型。
//Getting list of Contacts per ScacID
var scacContactListRes = $resource("api/SearchScacContact");
scacContactListRes.query({ scacID: $scope.scacID }, function (scacContactList) {
$scope.searchScacContactResults = scacContactList;
// This populates the page with the editable content of the first content in the list
$scope.onEditScacContact($scope.searchScacContactResults[0]);
});
相关文章:
- 访问布局信息是否也会导致浏览器重排
- 正在将数据主题添加到所有项目
- 动态地改变“”的URL;添加新项目”;链接使用javascript/jquery
- 如何检查管道中未定义的项目
- 有没有一种方法可以添加相同的项目val=“0”;4〃;到JavaScript中数组的每个对象
- 学生搜索项目jquery/javascript
- 如何获取不属于我项目的上一页的URL
- 从下拉框中选择用户信息,并使用进度计数器显示数据库中的选定项目
- 我的 Meteor 项目如何通过服务器端 MongoDB/集合查找查询可靠地显示信息
- 如何将特定项目信息链接到 emberjs 中项目列表中的模板
- 使用AngularJS grag$在ng中的第一个项目重复,并使用它在页面上以其他形式打开项目信息
- 如何显示每页显示多少项目的信息,AngularJs Pagination
- 单击列表中的项目->查看详细信息但没有输出?Firebase.child失败:第一个参数是无效路径
- 加载后的详细信息页面,一旦一个项目被点击
- 需要从检查项目通过javascript和php拉数据库信息
- 我有一个包含 24 个项目的目录,当单击一个项目时,我想隐藏 23 个项目并显示有关所选项目的更多信息
- Select2:如何为选中的项目添加额外的信息
- 在鼠标悬停的工具提示中显示单个项目的详细信息
- Ext 4 beta -显示面板详细信息视图中的多个项目
- 如何在asp.net中使用javascript显示与所单击项目相关的信息