gpt4 book ai didi

javascript - Angularjs:如何捕获 标记中的文本并在我的 Controller 中使用它

转载 作者:行者123 更新时间:2023-11-28 00:31:38 24 4
gpt4 key购买 nike

我需要捕获按下编辑按钮的行的 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>

这是我的 Controller 代码的一部分,我需要在其中访问特定的 {{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;
});
});

};

我需要访问 post.id位于 label 中和post.title它被包裹在 <td> 中元素。 ng-model不适用于这些类型的元素,所以我不能使用它。

最佳答案

您可以将 post 参数传递给您的函数,例如 showCustom(post)

<div id="editbtn" ng-click="showCustom(post)" class="circular ui icon button">
<i class="edit icon"></i>
</div>

您可以在 Controller 中使用它。

$scope.showCustom = function(post) {
var postId = post.id; //Get id
var title = post.title; //Get Title
//Rest of your code
}

关于javascript - Angularjs:如何捕获 <td> 标记中的文本并在我的 Controller 中使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28927557/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com