using System;
public class Employee
{
public int EmpID { get; set; }
public string EmpName { get; set; }
public string Gender { get; set; }
public string Salary { get; set; }
public string EmpAddress { get; set; }
public Employee()
{
}
}
using System;
using System.Collections.Generic;
using System.Web.Services;
using System.Data.SqlClient;
using System.Web.Script.Serialization;
using System.Web.Script.Services;
///<summary>
/// Summary description for EmployeeDetailService
///</summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class EmployeeDetailService : System.Web.Services.WebService
{
public EmployeeDetailService ()
{
}
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public void GetEmployeeDetail()
{
List<Employee> empList = new List<Employee>();
using (SqlConnection con = new SqlConnection ("Integrated Security=SSPI; Persist Security Info=False; Initial Catalog=Employee; Data Source=USER"))
{
SqlCommand cmd = new SqlCommand ("select * from emp", con);
con.Open();
SqlDataReade rdr = cmd.ExecuteReader();
while(dr.Read())
{
Employee empObj = new Employee();
empObj.EmpID = Convert.ToInt32(dr["EmpId"]);
empObj.EmpName=dr["Name"].ToString();
empObj.Gender = dr["Gender"].ToString();
empObj.Salary = dr["Salary"].ToString();
empObj.EmpAddress = dr["Address"].ToString();
empList.Add(empObj);
}
}
JavaScriptSerializer jsObj = new JavaScriptSerializer();
jsObj.Serialize(empList);
}
}
/// <reference path="angular.min.js" />
/// <reference path="../EmployeeDetailService.asmx" />
var myApp = angular.module("myModule", []);
var myController = function ($scope, $http)
{
$http.post('EmployeeDetailService.asmx/GetEmployeeDetail')
.then(function (response)
{
$scope.employees = response.data;
});
};
myApp.controller("myCont", myController);
<?xml version="1.0"?>
<configuration>
<system.web>
<compilationdebug="true" targetFramework="4.0"/>
<webServices>
<protocols>
<addname="HttpGet"/>
</protocols>
</webServices>
</system.web>
</configuration>
<!DOCTYPE html>
<html ng-app="myModule">
<head>
<script src="Scripts/angular.min.js" type="text/javascript"></script>
<script src="Scripts/Script.js"></script>
<style>
table, th, td
{
border: 1px solid grey;
border-collapse: collapse;
padding: 5px;
}
table tr:nth-child(odd)
{
background-color: #ffe6e6;
}
table tr:nth-child(even)
{
background-color: #ccffcc;
}
</style>
</head>
<body style="font-family:Arial; font-size:medium; color:darkblue">
<div ng-controller="myCont">
<h3>Using web service in AngularJS.</h3>
<br/>
<table>
<tr>
<th>EmpID</th>
<th>Name</th>
<th>Gender</th>
<th>Salary</th>
<th>Address</th>
</tr>
<tr ng-repeat="e in employees">
<td>{{e.EmpID}}</td>
<td>{{e.EmpName}}</td>
<td>{{e.Gender}}</td>
<td>{{e.Salary}}</td>
<td>{{e.EmpAddress}}</td>
</tr>
</table>
</div>
</body>
</html>
var myController = function ($scope, $http)
{
$http({
method : ‘GET’ ,
url :'EmployeeDetailService.asmx/GetEmployeeDetail'
})
.then(function (response)
{
$scope.employees = response.data;
});
};
myApp.controller("myCont", myController);
var myApp = angular.module("myModule", []);
var myController = function ($scope, $http, $log)
{
var successFunction=function(response)
{
$scope.employees = response.data;
$log.info(response);
}
var errorFunction= function (response)
{
$scope.error = response.data;
}
$http.get('EmployeeDetailService.asmx/GetEmployeeDetail')
.then(successFunction, errorFunction);
};
myApp.controller("myCont", myController);
var errorFunction= function (response)
{
$scope.error = response.data;
}
/// <reference path="angular.js" />
var myApp = angular.module("myModule", []);
var myController = function ($scope, $location)
{
$scope.myUrl = $location.absUrl();
$scope.myProtocol = $location.protocol();
$scope.myHost = $location.host();
$scope.myPort = $location.port();
};
myApp.controller("myCont", myController);
<!DOCTYPE html>
<html ng-app="myModule">
<head>
<script src="Scripts/angular.js"></script>
<script src="Scripts/Script.js"></script>
<style>
table, th, td
{
border: 1px solid grey;
border-collapse: collapse;
padding: 5px;
}
table tr:nth-child(odd)
{
background-color: #ffe6e6;
}
table tr:nth-child(even)
{
background-color: #ccffcc;
}
</style>
</head>
<body style="font-family:Arial; font-size:medium; color:darkblue">
<div ng-controller="myCont">
<h3>Using $location service in AngularJS.</h3>
<br/>
<table>
<tr><th>URL</th><td>{{myUrl}}</td></tr>
<tr><th>Protocol</th><td>{{myProtocol}}</td></tr>
<tr><th>Host</th><td>{{myHost}}</td></tr>
<tr><th>Port</th><td>{{myPort}}</td></tr>
</table>
</div>
</body>
</html>