mazdik / ng-mazdik

Angular UI component library
https://mazdik.github.io/ng-mazdik
MIT License
89 stars 34 forks source link

getOptions in service #5

Closed AltemirSantos closed 6 years ago

AltemirSantos commented 6 years ago

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 commented 6 years ago
    { 
      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 commented 6 years ago

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 commented 6 years ago

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

AltemirSantos commented 6 years ago

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 commented 6 years ago

fixed

AltemirSantos commented 6 years ago

Tks 👍