Link to home
Start Free TrialLog in
Avatar of Isaac Johnson
Isaac JohnsonFlag for United States of America

asked on

Create AngularJs parm using current date mmddyy to use as call parameter

I am trying to format the current date in my angularjs controller but the date is not being created
and passed to the API.

Am I using the correct syntax to create the mmddyy parm to pass to the API
This date will be used in the html ie, {{picdate}}

var app = angular.module('lobTotalsApp', []);
// Step 1 Execute API after creating date to passin
app.controller("LobTotalsController", function ($scope, $http) {
    $scope.Picture = function () {

        var picDate = format(Date(month(now()), day(now()), year(now())), "mmddyy")
        $http.get("/API/picture-of-the-day/api/PicOfTheDay/getpicbydate/" + picDate).then(function (response) {

            $scope.picDate = response.data
            
            
            alert("Capture success");
        }, function (error) {
            console.log(error);
        });
    };
//  This is first step in the Controller

Open in new window

Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

where is now() defined?

Did you mean Date.now()
Avatar of Isaac Johnson

ASKER

Yes.
I will make correction and test.
Also - where is format() defined?
I don't think I have the correct syntax for what I am attempting to do with the date.

I picked this format sequence off the web.

Can you show me what the format string should look like in angularJS
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Below is what I coded and it is working.
Thanks for your eye opening questions and solutions

// Picture of Day
app.controller("PicOfTheDayController", function ($scope, $http) {

    
    $scope.Picture = function () {

        function GetPicOfDay($http, $scope) {

            // variables to create the formatted date.
            var today = new Date();
            var dd = today.getDate();
            var mm = ("0" + (today.getMonth() + 1)).slice(-2); //January is 0!
            var yy = today.getFullYear().toString().substr(-2);
            var currentDateFormatted = "" + mm + dd + yy

            $http.get("/api/picture-of-the-day/api/PicOfTheDay/getpicbydate/" + currentDateFormatted).then(function (response) {
                $scope.Picture = response.data;
            }, function (error) {
                console.log(error);

Open in new window

You are welcome.