angular4输入属性(Input)

Input 是输入属性,用来定义组件的内的输入属性,主要用来实现父组件想子组件传递数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { Component, Input } from "@angular/core";

@Component({
selector: 'dex-counter'
})
export class CounterComponent {

// 变量
_count: number = 0;
biggerThanTen: boolean = false;

constrcutor() {
}

// @Input('value') count: number = 0;

// set
@Input()
set count(num: number) {
this.biggerThanTen = num > 10;
this._count = num;
}

get count():number {
return this._count;
}
}

ngOnChanges

0%