Trying to append a GET URL with a date, but it needs to be in the format "yyyyMMdd00".
Despite trying all the solutions here:
AngularJS - convert dates in controller
and
Binding value to input in Angular JS
I can only ever produce dates in the medium style format: dateFrom%3DFri+Feb+24+2017+00%3A00%3A00+GMT%252B0000+%28GMT+Standard+Time%29
Or nothing appears.
HTML (the h3 produces what I want to add to my url):
<ion-content class="item-input">
<label class="item-input">
<span class="input-label">Date From</span>
<input type="date" ng-model="dateFrom">
</label>
<h3>{{dateFrom | date: "yyyyMMdd00"}}</h3>
<a ui-sref="date({dateFrom:dateFrom})">Go</a>
</ion-content>
Controller
.controller("DateCtrl", function ($scope, $stateParams, dateService) {
$scope.events = dateService.getEvents($stateParams.dateFrom).then(function (events) {
$scope.events = events;
});
Factory:
.factory('dateService', function ($http) {
var events = [];
return {
getEvents: function (date) {
var params = {
dateFrom: date
}
return $http.get('URL', { params: params }).then(function (response) {
events = response.data.events;
return response.data.events;
});
And finally the routing:
.state('date', {
url: "/date/:dateFrom",
templateUrl: "templates/Date.html",
controller: "DateCtrl"
})