Gbuomprisco / ngx-chips

Tag Input component for Angular
MIT License
902 stars 359 forks source link

New tag added as anonymous object instead of class #849

Open kenger opened 5 years ago

kenger commented 5 years ago

PLEASE MAKE SURE THAT:

I'm submitting a ... (check one with "x")

[x] bug report => search github for a similar issue or PR before submitting
[ ] support request/question

Notice: feature requests will be ignored, submit a PR if you'd like

Current behavior

When I add a tag in the mapped array of I have an anonymous object.

puntiDiForza: Array(3)
0: OffertaPuntoDiForza {id: 1, deleted: false, testi: Array(1)}
1: OffertaPuntoDiForza {id: 3, deleted: false, testi: Array(1)}
**2: {id: 2, deleted: false, testi: Array(1), nomeVisualizzazione: "PDF2"}**

Expected behavior

I need the typed object for serialization.

puntiDiForza: Array(3)
0: OffertaPuntoDiForza {id: 1, deleted: false, testi: Array(1)}
1: OffertaPuntoDiForza {id: 3, deleted: false, testi: Array(1)}
**2: OffertaPuntoDiForza {id: 2, deleted: false, testi: Array(1)}**

Minimal reproduction of the problem with instructions (if applicable)

Code:

    <div class="input-group">
        <tag-input [(ngModel)]="model.puntiDiForza" name="punti-di-forza" 
                [onlyFromAutocomplete]="true"
                [displayBy]="'nomeVisualizzazione'"
                [identifyBy]="'id'">
            <tag-input-dropdown [showDropdownIfEmpty]="true"
                                [dynamicUpdate]="false"
                                [focusFirstElement]="true"
                                [displayBy]="'nomeVisualizzazione'"
                                [identifyBy]="'id'"
                                [autocompleteItems]="puntiDiForza">
                <ng-template let-item="item" let-index="index">
                    {{ item.nomeVisualizzazione }}
                </ng-template>
            </tag-input-dropdown> 
        </tag-input>
    </div>

I tried with (onAdding) but with the same result

  public toPuntoDiForzaObj(tag: any): Observable<OffertaPuntoDiForza> {
    let jsonConvert: JsonConvert = new JsonConvert();
    let tagObj = jsonConvert.deserializeObject(tag, OffertaPuntoDiForza); //tagObj is a real typed Object

    return of(tagObj);
  }

What do you use to build your app?. Please specify the version

Standard Angular app

Angular version:

Angular 7.1.0

ngx-chips version:

2.0.0-beta.0

Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]

all