Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
  <table  class="table">
            <thead>
                <tr><th>pcat</th><th>psub</th><th>ocas</th><th>metal</th><th>Edit</th></tr>
            </thead>
            <tbody>
<tr ng-repeat="a1 in co">
<td>{{a1.pcat}}</td><td>{{a1.psub}}</td><td>{{a1.ocas}}</td><td>{{a1.metal}}</td><td><input type="hidden"/><input type="button" id="b1" value="Edit" ng-click=edit(a1) /></td></tr>
            </tbody>
        </table> 


$scope.edit = function (a1) {
        alert(a1.data);
        $scope.da = a1.data;
    };


What I have tried:

i used ng-init but didn't worked
Posted
Updated 4-Nov-17 21:44pm

1 solution

refer this check the corrections,
 alert(a1.data); 
// there is no property with data, you will have to use any one of the properties (pcat,psub,ocas,metal) in the object  

alert(a1.pcat);
    $scope.da = a1.pcat;


<!DOCTYPE html>
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>

    <script>
        var app = angular.module('myApp', []);
        app.controller('myCtrl', function ($scope) {
            var data = [
                { pcat: 'pcat-1', psub: 'psub-1', ocas: 'ocas-1', metal: 'metal-1' },
                { pcat: 'pcat-2', psub: 'psub-2', ocas: 'ocas-3', metal: 'metal-4' },
                { pcat: 'pcat-3', psub: 'psub-2', ocas: 'ocas-3', metal: 'metal-4   ' },
            ];
            $scope.co = data;
            $scope.edit = function (a1) {
                alert(a1.pcat); 
                $scope.da = a1.pcat;
            };
            
        });
    </script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">
     
    <table class="table">
        <thead>
            <tr><th>pcat</th><th>psub</th><th>ocas</th><th>metal</th><th>Edit</th></tr>
        </thead>
        <tbody>
            <tr ng-repeat="a1 in co">
                <td>{{a1.pcat}}</td>
                <td>{{a1.psub}}</td>
                <td>{{a1.ocas}}</td>
                <td>{{a1.metal}}</td>
                <td><input type="hidden" /><input type="button" id="b1" value="Edit" ng-click=edit(a1) /></td>
            </tr>
        </tbody>
    </table>
</body>
</html>

Demo: Plunker[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900