OnInit class abstract

Implement to execute ngOnInit after the first change-detection completed.

ngOnInit is called right after the component or directive's data-bound properties have been checked for the first time, and before any of its children have been checked. It is normally only invoked once when the directive is instantiated:

@Component(
  selector: 'user-panel',
  directives: const [NgFor],
  template: r'''
    <li *ngFor="let user of users">
      {{user}}
    </li>
  ''',
)
class UserPanel implements OnInit {
  final RpcService _rpcService;

  List<String> users = const [];

  UserPanel(this._rpcService);

  @override
  void ngOnInit() async {
    users = await _rpcService.getUsers();
  }
}

Warning: As part of crash detection AngularDart may execute ngOnInit a second time if part of the application threw an exception during change detection.

Constructors

OnInit()

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

ngOnInit() → void
Executed after the first change detection run for a directive.
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