Utilize data from API responses to configure settings in angular-datepicker using pickadate.js

I am attempting to configure the options for the angular-datepicker, which is utilizing pickadate, by fetching data from a web-api call.

Here is my current code:

<label for="datepicker">Date:</label>
<input type="text" id="datepicker" pick-a-date="date" pick-a-date-options="dpoptions" placeholder="Select date" />

This is my JavaScript file:

var ServiceBasePath = "http://localhost:29050/api/";
var app = angular.module('myproj', ['angular-datepicker', 'ngTouch']);
app.controller('mycontroller', function ($scope, $http) {

        $scope.dpoptions = {
        format: 'ddd, dd-mm-yyyy',
        min: new Date(),
        max: _max
        }

        $http.get(ServiceBasePath + 'settings/1').
            success(function (data) {
                _max = data.MaxDays;
                $scope.config.duration = data.Duration;
                });
        }

When I define the value of _max initially and exclude the service results, everything works smoothly. It seems that the issue lies in the fact that the service response is not received before the datepicker initializes, although it functions fine for another field (not related to the datepicker):

                    <label>Duration (in minutes):</label>
                    <input type="number" id="duration" ng-model="duration" min="{{config.duration}}"  />

Is there a way to ensure the datepicker settings are loaded from the $http.get results?

Answer №1

modify

    $http.get(ServiceBasePath + 'settings/1').
        success(function (data) {
            $scope.dpoptions.max = data.MaxDays; //update this to a scope variable
            $scope.config.duration = data.Duration;
            });
    }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to utilize an Angular service method from a controller?

As a newcomer to Angular, I have created an 'Employee Search' Service module. Let's take a look at the code: // Employee Search Service app.service('employeeSearchService', function($http, resourceServerAddress){ this.empList ...

Encountering difficulties with managing the submit button within a ReactJS form

As I work on creating a User registration form using React JS, I encounter an issue where the console does not log "Hello World" after clicking the submit button. Despite defining the fields, validations, and the submit handler, the functionality seems to ...

Select dates within a range using jQuery UI datepicker

Looking to implement the jQuery UI datepicker on my asp.net aspx page, I aim to enable range selection and include an OK button on the calendar. After discovering a tutorial demonstrating this functionality at the following link: jQuery UI Datepicker - Ra ...

Enhance User Experience with JQuery Autocomplete for Internet Explorer 8 Using ASMX Web Services

Help Needed! I have been trying to implement a Web Service (ASMX) file on my website. When I access and query the page, I receive the desired results. The problem arises when I attempt to add autocomplete functionality to a textbox in my ASP.NET applicati ...

Retrieving the chosen option from a datalist component

I am in the process of designing an autocomplete feature for my personal use. Essentially, my directive generates an input field where I can input my search queries and a datalist that will hold the values retrieved from the server. template: function (el ...

Troubleshooting the malfunction of jQuery's change() function

There are three HTML select tags on my page. I want these three select tags to function as follows: When I change selectA, selectB should automatically update based on the selection in selectA. Similarly, when an option in selectB is created, changing se ...

Why can't I capture the text within this particular div using .text?

Trying to extract specific text from a website in Chrome's developer console. For example, here is the code snippet: <div class="someClass">This is some text!</div> Expected it to work with this command, but it returns 'undefined&a ...

Experiencing difficulty creating a realistic typing effect with JavaScript that would accurately simulate typing errors

I condensed everything into a single HTML file for easier testing of this specific section. The objective is to initially type Wx, then delete the x, pause for a second, and finally type elcome. Currently, the output is Wlcome. I have attempted various m ...

Activation of Angular Watch upon newValue alteration

Is there a way to prevent triggering the watch multiple times when changing values based on other values in a repeat loop? Here is my current watch function: $scope.$watch('objlist', function(newValue, oldValue) { $scope.counter += 1; ...

JavaScript: The difference in behavior between using Array(3).map() and [...Array(3)].map() is quite puzzling

When using Chrome Version 125.0.6422.76 (Official Build) (64-bit), I have encountered a strange issue with the Array constructor. https://i.sstatic.net/6HSUS2gB.png It seems that the length of array 'a' is correctly stored as '3' inte ...

Uploading CouchDB document attachments using an HTML form and jQuery functionality

I am currently in the process of developing a web form that, upon submission, will generate a couchdb document and attach file(s) to it. I have followed tutorials and visited forums that suggest a two-stage process similar to futon's approach. While I ...

Is it possible to personalize the default TimePicker or DatePicker on Android?

Is it possible for me to personalize the default DatePicker and TimePicker on Android? I typically use spinner mode, but I'd like the ability to customize different aspects such as fonts - including font type, size, and style - rather than just alteri ...

What are the steps to seamlessly incorporate and set up Node.js into a web application powered by CodeIgniter that is currently hosted on

After successfully deploying my Codeigniter based application to the online server, I now desire to incorporate instant messaging functionality using socket.io. This can be achieved by installing node.js. Can anyone provide guidance on how to install nod ...

Angular organizes the GET response in alphabetic order

Currently, I am working on developing an interactive table in Angular that displays information from a SQL database. The technology stack I have chosen to work with includes MSSQL, Express.js, and AngularJS. While logging the response in Node, I noticed t ...

How do I automatically redirect to a different URL after verifying that the user has entered certain words using Javascript?

I want to create a function where if a user input on the "comments" id matches any word in my FilterWord's array, they will be redirected to one URL. If the input does not match, they will be redirected to another URL. The checking process should onl ...

Adjust the primary scrolling section of a webpage to halt once it reaches a specific distance from the bottom of the viewport

I am facing a situation where I need to ensure that when scrolling down, a fixed pink menu bar at the bottom of the page does not overlap with the main blue content. This can be achieved by treating the blue content as an iframe positioned 60px from the bo ...

The visibility of the button is not functioning properly on iOS within the Kony platform

Currently, I am involved in a project using Kony and have encountered an issue where I need to hide a button based on a certain condition. I have implemented the code provided below, which functions correctly on Android devices but not on iOS. I have gone ...

Incorporating PHP in JS/jQuery AJAX for creating unique odd and even conditional layouts

My PHP code includes a loop that changes the layout of elements based on whether the $count variable is odd or even. For odd counts, an image appears on the left and text on the right. For even counts, it's the other way around. To load content dynam ...

Replace the phrase "add to cart" with "plus" and "minus" in Opencart

I am trying to customize the Add to Cart functionality in OpenCart 2.0.1.1 by replacing it with plus and minus buttons. I have successfully added the plus button, however, I am facing difficulty coding for the minus button. The code snippet below shows w ...

Show notifications after being redirected to a new page

My goal is to submit a form and have the page redirected to a different URL upon submission. Currently, everything works as expected, but there is an issue with the timing of the toast message. The toast message appears immediately after the user clicks th ...