2017-02-20 41 views
0
- 
<ArrayOftblEmp xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/WebApplication6"> <tblEmp> <Age>21</Age> <Id>1</Id> <Name>Narasingh</Name> <Salary>15000.0000</Salary> </tblEmp> <tblEmp> <Age>22</Age> <Id>2</Id> <Name>johny</Name> <Salary>20000.0000</Salary> </tblEmp> <tblEmp> <Age>50</Age> <Id>3</Id> <Name>Patrik</Name> <Salary>300000.0000</Salary> </tblEmp> <tblEmp> <Age>45</Age> <Id>4</Id> <Name>Gudumba Shankar</Name> <Salary>250000.0000</Salary> </tblEmp> </ArrayOftblEmp> 

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


app.controller('dbCtrl', function ($scope,$http) { 
$scope.test = 'hihi'; 

$scope.dataemp = function() { 
    $scope.test2 = 'check'; 
    debugger; 
    $http.get('http://localhost:1574/api/emp') 
      .then(function (response) { 
       $scope.data = response.data; 
      }); 
}; 

});無法使用angularjs從web api獲取數據

我無法將其綁定到html頁面。 http://codepen.io/NateBen/pen/WopZje

通知JS部分,它是一個ES6,你可以切換到香草JS,並注意以下代碼:如何使用angularjs

+0

從web api獲取數據,但我無法使用angularjs將其綁定到html頁面 –

回答

0

我有該操作一個不錯的演示,在這裏顯示在表這個數據:

var root = 'https://jsonplaceholder.typicode.com'; 
$http({ 
    method: 'GET', 
    url: root + '/users/' 
}).then(function (response) { 
    // handle success 
    console.log(response); 
    $scope.dataUsers = response.data; 

}, function (response) { 
    // handle error 
    console.log(response); 
}); 

$ scope.dataUsers是你的模型,你應該綁定到HTML,與中繼器。