Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am trying to bind "date.datefrom" and "date.dateto" from my datepicker to the end of my $http GET URL.

I can't seem to it, everything I try comes back as "undefined" but I've got my $scope in the controller, and the two sides work fine independent of each other - that is, the date picker updates the H3 tags correctly so the controller must be working, and if I hardcode in a date in the factory under "datefrom"/"dateto" it works. I just can't get them to bind together...

Code as follows

    <ion-content class="item-input" ng-controller="DateCtrl">
<label class="item-input">
    <span class="input-label">Date From</span>
    <input type="date" ng-model="date.datefrom">
</label>

<h3>{{date.datefrom | date: "yyyyMMdd00"}}</h3>

<label class="item-input">
    <span class="input-label">Date To</span>
    <input type="date" ng-model="date.dateto">
</label>

<h3>{{date.dateto | date: "yyyyMMdd00"}}</h3>
<a href="#/date" class="button">GO</a>

Controllers

     .controller("DateCtrl", function ($scope, $stateParams, dateService) {
$scope.date = {
    datefrom: "Date From",
    dateto: "Date To"
};
console.log("Date Controller1 says: Hello World - I also work");
     })
      .controller("DateDetailCtrl", function ($scope, $stateParams, dateService) {
$scope.events = dateService.getEvents($stateParams.date).then(function (events) {
    $scope.events = events;
            console.log("Date Controller says: Hello World - I also work");
});
     })

Factory

     .factory('dateService', function ($http) {
var events = [];

return {
    getEvents: function (date) {
     var url = 'http://api.URL.com&date=',
    datefrom = 'date.datefrom',
    dateto = 'date.datefrom',
    key = "-";

        return  $http.get(url + datefrom + key + dateto).then(function (response) {
             events = response.data.events;
            return response.data.events;
        });
    },
    getCEvent: function (index) {
        return events.event[index];
    }
}
     })
share|improve this question

Assuming you are trying to navigate to a state which has fromDate and toDate as query params, you should pass them to your anchor tag. Something like this if your are using UI-Router

<a ui-sref="date({fromDate:date.fromDate,toDate:date.toDate})">Go</a>

where your target state name is data and it takes fromDate and toDate as params. Something like this

$stateProvider.state('date',{
  url : '/date?fromDate&toDate',
  controller : 'dateDetailsCtrl'
})

Also the factory should be using properties from date object instead of assinging string to variables

return {
    getEvents: function (date) {
     var url = 'http://api.URL.com&date=',
    datefrom = date.dateFrom,
    dateto = date.dateTo,
    key = "-";
...
share|improve this answer
    
I've tried using UI Router and the method you said and i couldn't get it to work. Says date.dateFrom is undefined. No matter what I try, this is the only response I ever seem to get. – Kyle Davidson yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.