I have used the following technologies in the article:
Here's the link for the previous part of this series: How to call WCF Service Using jQuery - Part 1.
This image contains my solution explorer.
AngularDemo.html file
- ng-app is an application name in angular which is unique in project.
- <html xmlns="http://www.w3.org/1999/xhtml" ng-app="AngularApp">
App.js file
- Here we can integrate angular project name in app.js.
- var app = angular.module('AngularApp', []);
AngularDemo.html file
- ng-controller is a specific controller for my project which I define in my body tag.
- <body ng-controller="AngularController">
Controller.js
- Here I used controller as an intermediate between service.js and app.js.
- The following GET method is used for getting all the records from service.
- app.controller('AngularController', ['$scope', '$http', 'AngularService', function ($scope, $http, AngularService) {
-
- $scope.formdata = {};
-
-
- AngularService.get().success(function (response) {
- $scope.Products = JSON.parse(response.d);
- });
Service.js
- Below i declared get service for fetching records from service.
- WCF Service URL is taken from my previous article.
- So you can download my service from there and used here.
- app.factory('AngularService', ['$http', function ($http) {
- return {
-
- get: function () {
- return $http({
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json; charset=utf-8'
- },
- url: 'http://www.wcfdemo.somee.com/ProductService.svc/LoadAllProductDetail',
- data: {}
- });
- }
- };
- }]);
AngularDemo.html file
- ng-repeat is a working like for, foreach loop in angular
- ng-click is like onclick event in javascript.
- {{ }} is a syntax for displaying data.
- <table class='table table-bordered'>
- <tbody>
- <tr>
- <th>Name</th>
- <th>Description</th>
- <th colspan="2">Action</th>
- </tr>
- <tr ng-repeat="Product in Products">
- <td>{{ Product.ProductName}}</td>
- <td>{{ Product.ProductDescription}}</td>
- <td><span><a href="javascript:void(0);" ng-click="edit(Product);">
- <img width="16" height="16" alt="Close" src="Image/Edit.jpg" /></a></span></td>
- <td><span><a href="javascript:void(0);" ng-click="delete(Product.Id);">
- <img width="16" height="16" alt="Close" src="Image/close.png" /></a></span></td>
- </tr>
- </tbody>
- </table>
Output
You can also test the output
here.