Diwakar Yadav
Diwakar Yadav

Reputation: 15

Angular JS expression not evaluating using $http service

This is Script.js

var app = angular
.module("myModule", [])
.controller("myController", function ($scope, $http) {
    $http.get(   
           url: 'EmployeeService.asmx/GetAllEmployees'
           )
          .then(function (response) { 
              $scope.employees = response.data;
           });
});

This is Htmlpage1.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.8/angular.min.js"></script>
    <script src="Scripts/Script.js"></script>


</head>
<body ng-app="myModule">
    <div ng-controller="myController">
        <table border="1" style="border:none;">
            <thead>
                <tr>
                    <th>Id</th>
                    <th>Name</th>
                    <th>Gender</th>
                    <th>Salary</th>
                </tr>
            </thead>
            <tbody>
                <tr ng-repeat="employee in employees">
                    <td>{{employee.id}}</td>
                    <td>{{employee.name}}</td>
                    <td>{{employee.gender}}</td>
                    <td>{{employee.salary}}</td>
                </tr>
            </tbody>
        </table>
    </div>
</html>

    The expression Id   Name    Gender  Salary
    {{employee.id}}     {{employee.name}}   {{employee.gender}}     {{employee.salary}} is not getting evaluated

   The values of the table are not displaying

Upvotes: 0

Views: 73

Answers (2)

Andres2142
Andres2142

Reputation: 2917

What event or who is making that request?

   var app = angular
   .module("myModule", [])
   .controller("myController", function ($scope, $http) {

       //when the page is ready
       angular.element(document).ready(function() {
           $http({ method: 'GET',
                   url: 'EmployeeService.asmx/GetAllEmployees'
           }).then(function (response) { 
                 $scope.employees = response.data;
           }).catch(function (err) {
               console.log('Error encountered : ' + err);
           });
       });           
});

Upvotes: 0

Bill P
Bill P

Reputation: 3618

$http.get() method gets the url parameter as a string, so you are not using it correctly. This is the correct syntax:

$http.get('EmployeeService.asmx/GetAllEmployees')

Read more: $http#get

IF the url is correct then your code should work with this change

Upvotes: 1

Related Questions