I have a generic method to get data from back-end and pass it to an array
Here is the code of the method, where I pass method for getting data, array and default value, where I need to write the first element id
interface fillDropdownOptionsInterface {
method: Observable<ListResultDtoOfDropdownOptionDto>;
items: SelectItem[];
defaultvalue?: number;
}
public static fillDropdownOptionsObj(ref: fillDropdownOptionsInterface): void {
ref.method.subscribe(r =>
r.items.forEach(value => {
ref.items.push({
label: value.name,
value: value.id,
});
ref.defaultvalue = ref.items[0].value;
})
);
}
here is how I call it
getQuoteTypes(): void {
const obj = {
method: this._quoteService.getQuoteTypesOptions(),
items: this.quoteTypes,
defaultvalue: this.quote.quoteTypeId,
};
DropdownHelpers.fillDropdownOptionsObj(obj);
}
and then I call it in the OnInit method.
My problem that when I want to get quoteTypeId at an HTML template like this, I got nothing.
<div class="col-4">
<p-dropdown
[disabled]="!quoteTypes"
[options]="quoteTypes"
autoWidth="false"
styleClass="w-100"
name="quoteType"
[autoWidth]="true"
[(ngModel)]="quote.quoteTypeId"
></p-dropdown>
</div>
{{ quote.quoteTypeId }}
I was trying to pass a pre-initialized value to pass it to function, and after this function need to rewrite it and pop outside rewrote value. Like this
this.quote.quoteTypeId = 99;
But on view, I still see 99.
So I guess the problem in this - function, not pop outside rewrote value (I mean this.quote.quoteTypeId). How I can fix this?
this.quote.quoteTypeId==obj.defaultvalue