Click here to Skip to main content
15,896,730 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am facing the issue for binding data in to cshtml file with angularjs.

if we hard coded directly in to $scope.results as follows

PHP
$scope.results=[{
                "user_id": "minebranch", "First Name": "minebranch", "Surname": "minebranch", "Client": "DEMO LABOUR PROVIDER (CLIENT)", "Branch": "DEMO LABOUR PROVIDER (CLIENT)", "Expr1": "minebranch", "pword": "minebranch",
                "centre_group_name": "Crunch Corporate", "group_description": "Crunch Corporate", "group_id": 105, "centre_id": 260013, "branch_id": 24
            }]


the binding process is working properly.But if I let them to bind from the DB(Checked and confirmed that the above hard coded result is getting) like the code line written in eventController,the binding will not happening.



Here is my controller and cshtml file.

PHP
eventModule.controller("eventController", function ($scope, EventsService) {

    EventsService.Getclientlogin().then(function (data) {
      $scope.results =[];

    $scope.results.push(angular.fromJson(data));

                
    }, function ()
    { alert('error while fetching talks from server') })

});


XML
<html data-ng-app="eventModule">
<body<table id="tb_SearchResult" class="table table-striped table-bordered table-condensed " data-ng-controller="eventController">


           <thead>
               <tr>
                   <th>client</th>
                   <th>Surname</th>

               </tr>



           </thead>
           <tbody>
               <tr data-ng-repeat="result in results">
 <td>
                       {{result.client}}
                   </td>
                   <td>
                       {{result.Surname}}
                   </td>


               </tr>
           </tbody>

</body>
</html>


Thank you,
soumya
Posted
Updated 5-Mar-15 19:57pm
v5
Comments
Have you debugged and see inside the Controller, whether after pushing the data to results, the data is there or not?
soumyaraj 6-Mar-15 2:27am    
Yes data is there in the form of json
[{
"user_id": "minebranch", "First Name": "minebranch", "Surname": "minebranch", "Client": "DEMO LABOUR PROVIDER (CLIENT)", "Branch": "DEMO LABOUR PROVIDER (CLIENT)", "Expr1": "minebranch", "pword": "minebranch",
"centre_group_name": "Crunch Corporate", "group_description": "Crunch Corporate", "group_id": 105, "centre_id": 260013, "branch_id": 24
}]
Do you see any errors in console? Please hit "Reply" button to reply me.
soumyaraj 6-Mar-15 3:37am    
when I use alert($scope.results[0])
it given the result '[' and when I use ($scope.results),it given the full result.
for alert($scope.results.Surname) it says undefined
Try like...

alert($scope.results[0].Surname)

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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