I am creating an Angular 4 application and I have two separate pages, a Detail page and an Edit page, each of which has its own component.
When a user edits a model on the Edit page, I redirect it back to the Details page as follows:
// This is within my RetailerEditComponent save(): void { this.retailerService.updateRetailer(this.retailer) .then(() => this.router.navigate(['/admin/retailer'])); }
On the admin / retailer page, I have a RetailerDetailComponent that looks like this:
export class RetailerDetailComponent { retailer: Retailer; public hasBeenUpdated: boolean = false; constructor( private retailerService: RetailerService, ) { console.log("in RetailerDetailComponent"); } }
How to set bool hasBeenUpdated to true from my other page?
Update:
I like the idea of EventEmitter, but the problem is working.
My RetailerService:
export class RetailerService { public OnRetailerUpdated = new EventEmitter();; updateRetailer(retailer: Retailer): Promise<Retailer> { this.OnRetailerUpdated.next(true); return new Promise((resolve, reject) => { apigClient.retailerVPut({}, retailer, {}) .then(function (result) { resolve(result.data[0]) }).catch(function (result) { reject(result) }); } }) }); } }
And in my RetailerDetailComponent:
RetailerDetailComponent export class implements LoggedInCallback {retailer: retailer;
public showError: boolean; constructor( private retailerService: RetailerService) { } ngOnInit(): void { this.retailerService .OnRetailerUpdated .subscribe(value => { this.showError = true; console.log('Event thingy worked') }); }
But the console message is not displayed
source share