[英]How to get value from hidden input in ng-repeated div using Angular.js
I have controller which send data to UI and map them using ng-repeat directive.Next thing that i want to do is to bind that data with hidden input form,and send it in another function in controller when click event occur.Any idea how to accomplish this? 我有控制器将数据发送到UI并使用ng-repeat指令映射它们。下一步要做的是将数据与隐藏的输入形式绑定在一起,并在发生点击事件时将其发送到控制器的另一个函数中。完成这个? My HTML looks like this:
我的HTML看起来像这样:
<div class="card card-block" ng-repeat="admin in showAdmins">
<h3 class="card-title">{{admin}}</h3>
<input type="hidden" ng-value="{{admin}}" ng-model="username"/>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
<button class="btn btn-primary" ng-click="searchAdmins(username)">SeeProfile</button>
</div>
And controller: 和控制器:
$scope.searchAdmins = function(username){
//To do
};
github.users('admins.php').then(function(users){
$scope.showAdmins = users;
console.log($scope.showAdmins);
});
I think you want to do this: 我认为您想这样做:
<div class="card card-block" ng-repeat="admin in showAdmins">
<h3 class="card-title">{{admin}}</h3>
<input type="hidden" ng-model="admin"/>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
<button class="btn btn-primary" ng-click="searchAdmins(admin)">SeeProfile</button>
</div>
http://plnkr.co/edit/IzJkvLJoTHLtVzobWPpZ?p=preview http://plnkr.co/edit/IzJkvLJoTHLtVzobWPpZ?p=preview
var app = angular.module('app', []); var app = angular.module('app',[]);
app.controller('testctrl',function($scope) { app.controller('testctrl',function($ scope){
var users = [ var users = [
{
user : 'User1'
}, {
user : 'User2'
}, {
user : 'User3'
}
]; ];
$scope.showAdmins = users; $ scope.showAdmins =用户;
$scope.searchAdmins = function(user){ $ scope.searchAdmins =函数(用户){
alert(user); 警报(用户); }
}
}); });
Html HTML
<div ng-repeat="admin in showAdmins">
<h3 >{{admin.user}}</h3>
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
<button class="btn btn-primary" ng-click="searchAdmins(admin.user)">SeeProfile</button>
Thank you, Chaitanya 谢谢你,柴坦亚
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.