子组件:
import { Component} from '@angular/core';
@Component({
selector: 'app-test',
templateUrl: './app-test.component.html',
styleUrls: ['./app-test.component.scss']
})
export class TestComponent implements OnInit {
testBoolean: boolean;
constructor() { }
}
父组件
.html
<app-test [testBoolean]="testBoolean"></app-test>
<button (click)="onClick()"></button>
.ts
import { Component, Input} from '@angular/core';
@Component({
selector: 'app-test1',
templateUrl: 'app-test1.component.html',
styleUrls: ['app-test1.component.scss']
})
export class TestParentComponent {
@Input() testBoolean;
constructor() { }
onClick() {
console.log(this.testBoolean);
}
}
当我运行应用程序时出现以下错误:
无法绑定到“ testBoolean”,因为它不是“ app-test”的已知属性。
答案 0 :(得分:0)
丹是对的,
import { Component,Input} from '@angular/core';
@Component({
selector: 'app-test',
templateUrl: './app-test.component.html',
styleUrls: ['./app-test.component.scss']
})
export class TestComponent implements OnInit {
@Input() testBoolean: boolean;
constructor() { }
}