Reputation: 13
I'm inserting data from database in my table and fill the rows with it. When I click on a row a form is loaded and the table disappears. My problem now is that I want to transfer/copy the data from the clicked row into the labels of the form, so how can I get the right data into my labels?
Sample Table.html:
<tr class="mytr" ng-repeat="person in persons | ng-click="loadForm()">
<td class="{{person.status}}">{{person.PersonId}}</td>
<td class="{{person.status}}">{{person.Name}}</td>
<tr>
Sample showForm.html:
<form action="">
<label for="pid">{{person.PersonId}}</label>
<label for="name">{{person.Name}}</label>
</form>
From Controller:
$scope.loadForm()= function () {
$scope.content =
'http://localhost:49929/App_Plugins/Person/showForm.html';
}
Upvotes: 0
Views: 102
Reputation: 6983
Try this.
<tr class="mytr" ng-repeat="person in persons | ng-click="loadForm(person)">
<td class="{{person.status}}">{{person.PersonId}}</td>
<td class="{{person.status}}">{{person.Name}}</td>
<tr>
pass the person object as a parameter to the loadForm
function.
Update the loadForm
to recieve a parameter.
$scope.loadForm = function (person) {
$scope.content = 'http://localhost:49929/App_Plugins/Person/showForm.html';
$scope.person = person;
}
Upvotes: 1
Reputation: 41397
pass the person object as a parameter to the function and assign it to a separate scope variable. Then use that variable in the form
ng-click="loadForm(person)"
loadForm(person){
$scope.formObj = person
}
<form action="">
<label for="pid">{{formObj.PersonId}}</label>
<label for="name">{{formObj.Name}}</label>
</form>
Upvotes: 1