简体   繁体   中英

*ngIf directive in Angular

I'm getting data from my backend server

proyecto: Proyecto;
ngOnInit(): void {
// subscribe START
    this.route.paramMap.subscribe(
            params => {
                const id = params.get('id');
                console.log('MainContent:Proyecto Seleccionado: ', id);
                this.dataService.getDatosCabeceraProyecto(id)
                    .subscribe(
                        (data: Proyecto) => this.proyecto = data,
                        (err: any) => console.log(err),
                        () => console.log('MainContent: datos de proyecto recogidos')
                    );
            });
// subscribe END
}

But If I use ngIf directive I don't see anything

html

But I get the data

安慰

Any idea Please? Thanks

Try checking with some data inside the result with *ngIf and see if u get the results first.

For eg -

*ngIf="proyecto.ID==X000128" 

This will give you an idea of what it accepts.

Use can use this and check as example

<div *ngIf="!!proyecto">

reference use of !! Operator

Ref: https://stackoverflow.com/a/784946/6923146

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM