Nested components Flashcards
How many was to use a component?
Two. As a directive or as a routing target.
Component can be nested if
it has a selector so it can be used. It can optionally communicate with its container
How nested component receives information from container
By using @Input properties
Nested component outputs information to the container by … ?
emitting events
@Input decorator can decorate any property in nested component. How does container pass data to nested component?
By property binding.
When does the ngOnChanges event of nested component is generated?
Any time the container data changes and is bound to @Input property of the nested component.
@Output decorator decorates
any property of the nested component class. Property must be an event. This is the only way a nested component can pass data to the container.
The way to do is for example to setup an event, that by itself emits event to container. onClick() { this.notify.emit(…); }
Then on the container HTML when calling the directive use event binding (notify)=’onNotify($event)’ to call a method in container component.
Pluralsight courses to check out
Angular component communication