Good day. Please tell me how to extract variables from the URL string and substitute into the code Angular (parsing json):

var sortApp = angular.module('sortApp', []) var vm = this; vm.name = '2017-11-01'; sortApp.controller('mainController', function($scope, $http) { $scope.sortType = 'stat_date'; $scope.sortReverse = false; $scope.searchFish = ''; $http.get('http://www.mydomen.ru/all?from=01.01.2017&to=01.12.2017').success(function(data) { $scope.Users = data; }); }); 

This script will be executed as a result of the transition to the page, such as http://www.getmyjson.ru/getreportjson.html I would like to send two variables for this url - Date of the beginning of the period and Date of the end of the period . For example, like this: http://www.getmyjson.ru/getreportjson.html?data1=01.01.2017&data2=01.12.2017 And then substitute these variables here:

 $http.get('http://www.mydomen.ru/all?from=data1&to=data2').success(function(data) 

    1 answer 1

    To search in the Url, use the $ location service, you can read more in the official documentation , in this case the current URL will be taken.

      var sortApp = angular.module('sortApp', []) var vm = this; vm.name = '2017-11-01'; sortApp.controller('mainController', function($scope, $http, $location) { //необходимо добавить его в зависимости $scope.sortType = 'stat_date'; $scope.sortReverse = false; $scope.searchFish = ''; $http.get('http://www.mydomen.ru/all', {params:{ from: $location.search('data1'), to: $location.search('data2')} }).success(function(data) { $scope.Users = data; }); });