" @ angular / core":" ^ 4.0.0"
"打字稿":" ~2.3.3"
@Component({
selector: 'app-parent',
templateUrl: '<app-child [data]="test"></app-child>'
})
export class ParentComponent {
test: number = 123;
}
/****/
class Test {
name: string
}
@Component({
selector: 'app-child',
templateUrl: '<div></div>',
})
export class ChildComponent {
@Input() data: Test;
}
为什么ChildComponent不发誓data属性不属于Test数据类型? 打字稿或角度如何能够检查组件的传入属性?
答案 0 :(得分:2)
您可以使用instanceof
if(data instanceof Test) { console.log(true); }