Ionic-datepicker - How to render after $http?

Asked

Viewed 111 times

0

Good afternoon.

Next...I don’t know for sure if my doubt is about Ionic or about Angularjs.

I am implementing the code below

$scope.datepickerObject = {
              titleLabel: 'Escolha a Data',  //Optional
              todayLabel: 'Hoje',  //Optional
              closeLabel: 'Fechar',  //Optional
              setLabel: 'Ok',  //Optional
              setButtonType : 'button-assertive',  //Optional
              todayButtonType : 'button-assertive',  //Optional
              closeButtonType : 'button-assertive',  //Optional
              inputDate: new Date(),  //Optional
              mondayFirst: true,  //Optional
              disabledDates: arDatas, //Optional
              weekDaysList: '', //Optional
              monthList: '', //Optional
              templateType: 'modal', //Optional
              showTodayButton: 'true', //Optional
              modalHeaderColor: 'bar-positive', //Optional
              modalFooterColor: 'bar-positive', //Optional
              from: new Date(), //Optional
              to: new Date(2018, 8, 25),  //Optional
              callback: function (val) {  //Mandatory
                datePickerCallback(val);
              },
              dateFormat: 'dd-MM-yyyy', //Optional
              closeOnSelect: true, //Optional
            };


            var datePickerCallback = function (val) {
          if (typeof(val) === 'undefined') {
            console.log('No date selected');
          } else {
            console.log('Selected date is : ', val)
            $scope.dataConsulta = val.toISOString().slice(0,10);
            this.dataConsulta = val.toISOString().slice(0,10);
          }
        };

If I put this on JS, it works great, but if I put this inside a $http, it doesn’t work. I don’t know how to render this object after Ajax is finished.

  • "within a $http" - you mean 'inside the callback in case of a successful $http request', 'inside a file. js that get via $http', or something else? Clarify your question a little more, please.

  • Hi. I’m sorry if I wasn’t clear. I’ll try to explain.... If you take this block of code and simply put it into the JS, inside a controller it works perfectly. However, what I need is to pull the disabled dates via Ajax from a database. So, as this plugin has no Setdisableddata function for example, I need to take this whole block of code and put inside the $http Success. When I do this, HTML has already been rendered before the execution of $http. Got it?

  • Have you ever just tried to update the collection $scope.datepickerObject.disabledDates[] with the new dates? You don’t need to recreate the control.

  • Unfortunately, it didn’t work. He set up the calendar properly, but he did not disable the dates I put in the $Scope.datepickerObject.disabledDates = arData collection;

  • I believe so you are trading one object for another (disabledDates = arDatas). Try to add the received values to the existing object ($scope.datepickerObject.disabledDates.concat(arDatas))

  • Putz...doesn’t work either. If I initialize the object with any date disabled, it works. If I want to add more dates after pulling from the database, it doesn’t work.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.