AfterContentChecked class abstract
Implement this interface to get notified after every check of your directive's content.
Examples
Try this live example from the Lifecycle Hooks page:
template: '''
<div>-- projected content begins --</div>
<ng-content></ng-content>
<div>-- projected content ends --</div>
<p *ngIf="comment.isNotEmpty" class="comment">{{comment}}</p>
''',
class AfterContentComponent implements AfterContentChecked, AfterContentInit {
String _prevHero = '';
String comment = '';
// Query for a CONTENT child of type `ChildComponent`
@ContentChild(ChildComponent)
ChildComponent contentChild;
@override
void ngAfterContentInit() {
// contentChild is set after the content has been initialized
_logIt('AfterContentInit');
_doSomething();
}
@override
void ngAfterContentChecked() {
// contentChild is updated after the content has been checked
if (_prevHero == contentChild?.hero) {
_logIt('AfterContentChecked (no change)');
} else {
_prevHero = contentChild?.hero;
_logIt('AfterContentChecked');
_doSomething();
}
}
// ...
}
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
ngAfterContentChecked(
) → void -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited