I'm building an Angular 4 application and I have 2 separate pages, a Detail page and an Edit page, each with their own component.
When the user edits the model on the Edit page, I redirect them back to the Details page like this:
// This is within my RetailerEditComponent
save(): void {
this.retailerService.updateRetailer(this.retailer)
.then(() => this.router.navigate(['/admin/retailer']));
}
In 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 can I set the bool hasBeenUpdated to true from my other page?
Update:
I like the idea of the EventEmitter, but running into problems.
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:
export class RetailerDetailComponent 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 doesn't show up
new EventEmitter< boolean >();