I am new to AngularJs
and using it in a web form
My Code is as below
var app = angular.module('demoApp', [])
app.controller('usrController', function ($scope, $http, $window) {
$scope.userdata = {};
var post = $http({
method: "POST",
url: "Index.aspx/GetData",
dataType: 'json',
data: {},
headers: { "Content-Type": "application/json" }
}).success(function (data, status) {
console.log(data);
$scope.userdata = data.d;
}).error(function (data, status) {
$window.alert(data.Message);
});
});
My WebMethod code is as below
[WebMethod]
public static string GetData()
{
DataTable dt = Helper.UserList("sp_GetSearchList");
string JSONString = string.Empty;
JSONString = JsonConvert.SerializeObject(dt).ToString();
return JSONString;
}
My JSONString returns perfect json but I got error as
TypeError: $http(...).success is not a function
I have seen a lot of answers on Stack overflow but none of them actually solved this.
Extended Question
After using the following code it solved my question
var app = angular.module('demoApp', [])
app.controller('usrController', function ($scope, $http, $window) {
$scope.userdata = {};
$http.post("Index.aspx/GetData", {}).
then(function (response) {
console.log(JSON.parse(response.data.d));
$scope.userdata = JSON.parse(response.data.d);
});
},
function(error) {
});
My front end binding is this
<body data-ng-app="demoApp">
<form id="form1" runat="server">
<div data-ng-controller="usrController">
<table>
<tr>
<th>Sl No</th>
<th>User ID</th>
<th>Employee ID</th>
<th>Employee Name</th>
<th>Birth Date</th>
</tr>
<tr data-ng-repeat="data in userdata">
<td>{{data.ID}}</td>
<td>{{data.UserID}}</td>
<td>{{data.EmployeeID}}</td>
<td>{{data.EmpName}}</td>
<td>{{data.BirthDate}}</td>
</tr>
</table>
</div>
</form>
</body>
The data comes perfectly in console.log
but its not binding in front end.
Help me where I am wrong.Thanks in advance
then
function instead ofsuccess
function because it has expired. – Earingdata.d
but how to use theerror
– Allerieuserdata
object structure. – Earingdatatable
and convert it to` json` so I have no user class. See theGetData()
Method – Allerie