I know in general, one should instantiate instance variables and dependencies in the constructor, whether it is injected, new
'ed up, or from a @ngrx/store
select()
:
@Component
export class MyCoolComponent implements OnInit {
public coolObservable$: Observable<any>;
public myItems$: Observable<Item[]>;
constructor(private myCoolService: CoolService, private store: Store) {
// Instantiate the Observables here?
this.coolObservable$ = Observable.of('cool!');
this.myItems$ = this.store.select('items');
}
public ngOnInit() {
// Or instantiate the Observables here?
this.coolObservable$ = Observable.of('cool!');
this.myItems$ = this.store.select('items');
}
}
What is the best practice in Angular
?