ngOnInit vs ionViewDidLoad in ionic 2 or ionic 2+
问题 Which one will I use for initializing data and why? ngOnInit() { this.type = 'category'; this.getData(); this.setData(); } ionViewDidLoad() { this.type = 'category'; this.getData(); this.setData(); } 回答1: ngOnInit is a life cycle hook called by Angular2 to indicate that Angular is done creating the component. ionViewDidLoad is related to the Ionic's NavController lifeCycle events. It runs when the page has loaded. This event only happens once per page being created. Basically both are good