Angularjs:如何捕获 <td> 标签中的文本并在我的控制器中使用它
Angularjs: How to capture the text in <td> tag and use it inside my controller
我需要捕获按下编辑按钮的行的 id 和标题值。
以下是我的ng-repeat的结构:
<tr ng-repeat="post in posts">
<td>
<div class="ui singlenum checkbox">
<input type="checkbox" id="unique-1">
<label for="unique-1">{{post.id}}</label>
</div>
</td>
<td>{{post.title}}</td>
<td>{{post.posted_on}}</td>
<td>{{post.is_moderated}}</td>
<td>
<div id="editbtn" ng-click="showCustom()" class="circular ui icon button">
<i class="edit icon"></i>
</div>
</td>
</tr>
这是我的控制器代码的一部分,我需要在其中访问特定的{{post.id}}
和{{post.title}}
值。
app.controller('SampleController', ['$scope', 'ModalService', function($scope, ModalService) {
$scope.showCustom = function() {
ModalService.showModal({
templateUrl: "complex/complex.html",
controller: "ComplexController",
inputs: {
id: // This is where I need to specify the id for which the edit button was pressed.
title: // This is where I need to specify the title for which the edit button was pressed.
}
}).then(function(modal) {
modal.element.modal();
modal.close.then(function(result) {
$scope.complexResult = "Name: " + result.name + ", age: " + result.age;
});
});
};
我需要访问label
中的post.id
和包装在<td>
元素中的post.title
。 ng-model
不适用于这些类型的元素,所以我不能使用它。
你可以
像showCustom(post)
一样post
参数传递给你的函数。
<div id="editbtn" ng-click="showCustom(post)" class="circular ui icon button">
<i class="edit icon"></i>
</div>
您可以在控制器中使用它。
$scope.showCustom = function(post) {
var postId = post.id; //Get id
var title = post.title; //Get Title
//Rest of your code
}
相关文章:
- 从我的控制器返回一个不同于200的代码以触发ajax错误,这被认为是一种好的做法吗
- 为什么不't我的变量在我的控制器中填充后在我的视图中呈现
- 为什么我的控制器没有启动函数.js脚本
- JQuery$.ajax()发布数据以调用我的控制器中的方法
- AngularJS:这个注入我的控制器有什么问题
- 无权访问我的控制器 Angular 中的属性.js 1.3
- Angularjs:如何捕获
标签中的文本并在我的控制器中使用它 - 需要从视图中获取一个变量值到我的控制器中
- NodeJS和Express - 将我的控制器和模型分开
- 试图让我的决心注入到我的控制器中,以便能够注入到 HTML 中
- 构建现实世界的AngularJS应用程序,我应该如何在html中声明我的控制器.我需要在索引中声明所有.html吗?
- 如何分离代码:我的控制器是否做了太多工作
- 我的控制器不工作
- AngularJS:如何判断我的控制器是否绑定到我的ng-repeat指令元素?我的数据没有显示
- 如何将项目id传递给我的控制器以进行删除方法
- 如何在我的控制器中调用一个函数,该函数也被用作视图的范围
- Angular无法识别我的控制器
- 我希望我的控制器在做其他事情之前等待我的指令完成
- 不能从我的控制器中设置select value, Angular JS
- 为什么我的GSP拉在我的AngularJS javascript文件,但不执行我的控制器函数