angular - ngx-loading Toggling from another component -
i'm using ngx-loading , want able trigger it's showing/hiding children components. here have:
app.component
import { component, injectable } '@angular/core'; @injectable() export class appcomponent implements oninit{ public loading = false; constructor() { } loader() { this.loading = !this.loading; console.log(this.loading); } }
child component
import { appcomponent} '../app/app-component'; import { myservice } '../service/my-service'; @component({ selector:'child-component', templateurl: './child.component.html', providers: [appcomponent, myservice] }) export class childcomponent implments oninit { constructor(private loader: appcomponent, private service: myservice) {} ngoninit(): void { this.getdata(); } getdata() { this.loader.loader(); this.service.getdatafromservice().then(res => { this.mymodel = res; this.loader.loader(); } } }
if check logs this.loader toggle true false ngx-loading component isn't. if set initial value of loading in app.component ngx-loading displays wont hide. know loader working.
any ideas?
good day. reason change detection doesn't run. have created plunker make work. recommend use eventemmiter(output). main idea after promise finished run settimeout trigger changedetection.
this.getdata().then(() => { settimeout(() => { this.load.emit() })
have great day.
Comments
Post a Comment