The example in detail as give below.
The AngularJs code sample:
- var baseURL = "http://localhost:9669/";
- var cartURL = "api/AddToCart_API/GetMyCarts/";
- var EmailID = "[email protected]";
- var app = angular.module('cartOneAp', []);
-
- app.service("myCarts", function($http) {
- this.getShopingCart = function(urls, EmailID) {
- return $http({
- method: 'GET',
- url: baseURL + urls + '/' + EmailID
- });
- };
- });
-
- app.controller('baseController', function($scope, myCarts) {
-
- $scope.carts = null;
- $scope.email = EmailID;
-
- myCarts.getShopingCart(cartURL, $scope.email).then(function(resp) {
- if (resp !== undefined && resp !== null) {
- if (resp.data !== undefined && resp.data !== null) {
- $scope.carts = resp.data;
- console.log($scope.carts);
- }
- }
- });
- });
The HTML Code sample as given below:
- < div ng-app="cartOneAp">
- <div>
- <div ng-controller="baseController">
- <ul>
- <a href="/Products/Cart/{{ProductID}}">
- <l>{{ProductName}}}</l>
- </a>
- </ul>
- </div>
- </div>undefined</ div >
The Full Live (Angular +HTML) code as given below:
- <!DOCTYPE html>
- <html>
- <head>
- <link rel="stylesheet" href="style.css">
- <script src="https://code.angularjs.org/1.3.14/angular.js"></script>
- <script>
- var baseURL = "http://localhost:9669/";
- var cartURL = "api/AddToCart_API/GetMyCarts/";
- var EmailID = "[email protected]";
- var app = angular.module('cartOneAp', []);
-
- app.service("myCarts", function ($http) {
- this.getShopingCart = function (urls, EmailID) {
- return $http({
- method: 'GET',
- url: baseURL + urls + '/' + EmailID
- });
- };
- });
-
- app.controller('baseController', function ($scope, myCarts) {
-
- $scope.carts = null;
- $scope.email = EmailID;
-
- myCarts.getShopingCart(cartURL, $scope.email).then(function (resp) {
- if (resp !== undefined && resp !== null) {
- if (resp.data !== undefined && resp.data !== null) {
- $scope.carts = resp.data;
- console.log($scope.carts);
- }
- }
- });
-
- });
- </script>
- </head>
- <body ng-app="cartOneAp">
- <div>
- <div ng-controller="baseController">
- <ul>
- <a href="/Products/Cart/{{ProductID}}">
- <l>{{ProductName}}}</l>
- </a>
- </ul>
- </div>
- </div>
- </body>
- </html>