0

I've got an Angular controller

 myApp.controller('DateController', function ($scope) {
   $scope.date = {year: '2017', month: '08', day: '28'};
 });

I've got a second controller for the same module:

myApp.controller('rateList', ['$scope', function ($scope, $http) {
  $http.get('http://api.fixer.io/2000-01-03')
        .success(function (data) {
            $scope.rates = data.rates;      
        });
 }]);

In my HTML I've got a form linked to that controller, and I successfully can change the values of $scope.date. What I need now is to take the values from $scope.date and have those loaded into the url in the http call. The example url I hardcoded was 2000-01-03. But I do not want to use these hardcoded values, I wish to use the values from $scope.date

1
  • 1
    Why not just append it? "http://api.fixer.io/" + $scope.date.year + "-" + $scope.date.month + "-" + $scope.date.day Commented Aug 28, 2017 at 18:04

1 Answer 1

1

This will do

$http.get('http://api.fixer.io/' + $scope.date.year + '-' + $scope.date.month + '-' + $scope.date.day)

or better

var dateString =  $scope.date.year + '-' + $scope.date.month + '-' + $scope.date.day;

$http.get('http://api.fixer.io/' + dateString)
//your remaining code
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.