简体   繁体   中英

Updating view in angular after modal closes

Using Angular 5, what I want to do is update an attribute in the parent component as soon as the child component (modal dialog) is closed. Are all three of these methods viable ways of doing this? And which would be the fastest/least overhead?

Option a: So far I've always used a Subject() in a singular Service instance that I call in the modal component as it closes and subscribe to in the parent component to listen when it is called and thus update my attribute.

Option b: Would an EventEmitter be a viable option for this? I'm guessing I emit just about any value when the modal closes and in the parent onChange I can reevaluate my attribute?

Option c: I looked into Angular Lifecycle hooks and found things like ngOnChanges() and ngDoCheck() but neither of those seem to be useful. Are there other hooks that could be usable for this situation?

选项B是禁食且开销最小。

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