Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getOptions in service #5

Closed
AltemirSantos opened this issue Jul 27, 2018 · 6 comments
Closed

getOptions in service #5

AltemirSantos opened this issue Jul 27, 2018 · 6 comments

Comments

@AltemirSantos
Copy link

AltemirSantos commented Jul 27, 2018

I'm using ASP NET CORE in back-end, when I call the method this.service.getOptions for populate select-options component.
Method:

  loadOptions() {
    if (this.column.optionsUrl && this.service.getOptions) {
      this.loading = true;
      this.service.getOptions(this.column.optionsUrl, this._dependsValue).then((res) => {
        this._options = res;
        this.loading = false;
        this.setDefaultSelect();
      }).catch(error => {
        this._options = [];
        this.loading = false;
      });
    }
  }

This method receive one array the options.

@Input()
  set options(val: any[]) {
    this._options = val;
    if (this._options) {
      this.optionsCopy = [...val];
    }
    this.selectedName = this.getName();
  }

But with the request processing time, the initial value becomes undefined, and thus does not populate the ModalSelectComponent.

Getting in load, however when clicking under the modal page, the already processed value is loaded normally.

What can be done for this case?

@mazdik
Copy link
Owner

mazdik commented Jul 29, 2018

    { 
      name: 'x_id',
      tableHidden: true,
      formHidden: true
    },
    {
      name: 'x_name',
      keyColumn: 'x_id',
      optionsUrl: environment.host + '/dict/x_names',
      type: 'select-popup'
    },

from back-end: [{ x_id: 123, x_name: name123 }]
Have you tried this option?
For example, what are your columns?

@AltemirSantos
Copy link
Author

yes, it's exactly the same. The problem is that Promise does not populate the variable this._options at first, because it is still being rendered in the back end of the result, so the variable this.optionsCopy gets undefined.

@mazdik
Copy link
Owner

mazdik commented Jul 31, 2018

Is this error (undefined) displayed in the console?
Change detection is not working?

@AltemirSantos
Copy link
Author

The input-option.component not working now.

value is null in event valueChanged.


 onValueChange() {
    if (this.column.keyColumn) {
      this.keyColumnChange.emit({
        'column': this.column.keyColumn,
        'value': this.model
      });
    }
  }

this.model ever null.

@mazdik
Copy link
Owner

mazdik commented Aug 29, 2018

fixed

@AltemirSantos
Copy link
Author

Tks 👍

@mazdik mazdik closed this as completed Sep 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants