0

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? My HTML looks like this:

<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);

});
2
  • 2
    You don't need any hiddent, input, this is not jquery: just pass directly to ngclick the value you need admin or admin.username. Commented Sep 29, 2015 at 13:46
  • 1
    Thanks,now it works fine. Commented Sep 29, 2015 at 14:05

2 Answers 2

1

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>
Sign up to request clarification or add additional context in comments.

Comments

0

http://plnkr.co/edit/IzJkvLJoTHLtVzobWPpZ?p=preview

var app = angular.module('app', []);

app.controller('testctrl',function($scope) {

var users = [

{
  user : 'User1'
}, {
  user : 'User2'
}, {
  user : 'User3'
}

];

$scope.showAdmins = users;

$scope.searchAdmins = function(user){

alert(user); }

});

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.