import { Component, OnInit, Input, EventEmitter } from '@angular/core';
@Component({
selector: 'app-lifecycle',
templateUrl: './lifecycle.component.html',
styleUrls: ['./lifecycle.component.less'],
inputs: ['titleV:title', 'category', 'hello'],
outputs: ['city1:city']
})
export class LifecycleComponent implements OnInit {
titleV: any;
category: any;
hello: any;
public city1 = new EventEmitter();
public msg: any = '111';
public userinfo: string = 'a';
oldUserinfo: string = '';
constructor() {
console.log('00构造函数执行了---除了使用简单的值对局部变量进行初始化之外,什么都不应该做')
}
ngOnChanges() {
console.log('01ngOnChages执行了---当被绑定的输入属性的值发生变化时调用(父子组件传值的时候会触发)');
}
ngOnInit() {
console.log('02ngOnInit执行了--- 请求数据一般放在这个里面');
}
ngDoCheck() {
console.log('03ngDoCheck执行了---检测,并在发生 Angular 无法或不愿意自己检测的变化时作出反应');
}
ngAfterContentInit() {
console.log('04ngAfterContentInit执行了---在组件内容初始化之后调用');
}
ngAfterContentChecked() {
console.log('05ngAfterContentChecked执行了---组件每次检查内容时调用');
}
ngAfterViewInit(): void {
console.log('06 ngAfterViewInit执行了----组件相应的视图初始化之后调用(dom操作放在这个里面)');
}
ngAfterViewChecked() {
console.log('07ngAfterViewChecked执行了----每次做完组件视图和子视图的变更检测之后调用');
}
ngOnDestroy() {
console.log('08ngOnDestroy执行了····');
}
changeMsg() {
this.msg = "数据改变了";
}
}