0

I have to use "set timeout" to get the data from the parent component, so I can load it onto the page before the

I wish to replace this with a promise or async function. But I can't seem to get the syntax right.

Here is the code:

angular.
  module('fwcForms').
  component('tableFreetext', {
    templateUrl: _formPath+'/fwc-form/components/table-freetext.template.html',
    bindings: {
      model: '=',
    },
    controller: function TableFreetextController() {
      var self = this;
      this.$onInit = function() {
        setTimeout(()=>{
          self.newValue = self.model.dataRowsPlaceholder;
        },1000);
      }
    }
  });

I wish to replace:

setTimeout(()=>{
  self.newValue = self.model.dataRowsPlaceholder;
},1000);

With something like

let myPromise = new Promise(function() {
 return self.model.dataRowsPlaceholder
});

myPromise.then(data=>{
  self.newValue = self.model.dataRowsPlaceholder
});

But this does not work. It keeps saying "self.model.dataRowsPlaceholder" is 'undefined'.

2
  • what happens when you do "something like" that - you say you can't get the syntax right, so show what you did, so you can learn why your syntax is wrong
    – Bravo
    Commented Mar 4, 2022 at 1:58
  • "self.model.dataRowsPlaceholder" is from another component. When the current component loads, I can't put "self.model.dataRowsPlaceholder" on the page because it doesn't load fast enough.
    – jondar
    Commented Mar 4, 2022 at 3:35

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.