Created
March 17, 2017 00:02
-
-
Save A2H111/6bb09c3ffaf2260553f0bccfbe2f654a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference path="angular.js" /> | |
//Adding ui grid module as a depedency in app | |
var app = angular.module('app', ['ui.grid']); | |
//Controller function to load the data | |
app.controller('MainCtrl', function ($scope, $http, CustomerService) { | |
$scope.GetCustomer = function () { | |
$scope.gridOptions = { | |
columnDefs: [ | |
{ name: "CustomerID", displayName: "Customer ID" }, | |
{ name: "CompanyName", displayName: "Company Name" }, | |
{ name: "ContactName", displayName: "Contact Name" }, | |
{ name: "ContactTitle", displayName: "Contact Title" } | |
], | |
}; | |
//Calling the service using factory to populate the data | |
//and assigning data to gridOptions | |
CustomerService.GetCustomer().then(function (d) { | |
$scope.gridOptions.data = d.data; | |
}, function (d) { | |
alert(d.data); | |
}); | |
}; | |
//Call function to load the data on load | |
$scope.GetCustomer(); | |
}); | |
//Factory | |
app.factory('CustomerService', function ($http) { | |
var res = {}; | |
res.GetCustomer = function () { | |
return $http({ | |
method: 'GET', | |
dataType: 'jsonp', | |
url: 'api/Customer/GetCustomer' | |
}); | |
} | |
return res; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment