AngularJS + AngularJS Material + WooCommerce API. Запрос к API
В этом уроке мы сделаем первый запрос, используя woocommerce api, получив все заказы нашего магазина.
Код урока (script.js)
'use strict'
let app = angular.module('shop', ['ngMaterial', 'ngMessages', 'ngRoute']);
app.constant('API_URL', 'https://codetogether.ru/wp-json/wc/v3/');
app.config(function($httpProvider){
let auth = window.btoa('ck_000e1f9b7fd5200992a3fdb46f982c495ac721f8:cs_93ff2e592ee90b6c54d45abe78277b0992684979');
$httpProvider.defaults.headers.common.Authorization = 'Basic ' + auth;
});
app.config(function($mdThemingProvider, $routeProvider, $locationProvider){
$mdThemingProvider.theme('primary').primaryPalette('blue').accentPalette('orange');
$routeProvider
.when(
'/products', {
templateUrl: 'templates/products.html',
controller: 'productsController'
}
)
.when(
'/product', {
templateUrl: 'templates/product.html',
controller: 'productController'
}
)
.when(
'/product/:id', {
templateUrl: 'templates/product.html',
controller: 'productController'
}
)
.otherwise({
templateUrl: 'templates/orders.html',
controller: 'ordersController'
})
$locationProvider.html5Mode({
enabled: true
});
});
app.controller('mainController', function($scope) {
$scope.currentNavItem = 'orders';
});
app.controller('ordersController', function ($scope, $http, $mdDialog, API_URL) {
$http.get(API_URL + 'orders').then(
result => console.log(result)
);
});
app.controller('productsController', function ($scope, $http, $mdDialog) {
});
app.controller('productController', function ($scope, $http, $routeParams, $mdDialog, $filter, $location) {
});
0 Комментариев