Tôi đã tạo một thành phần con có một phương thức mà tôi muốn gọi.
Khi tôi gọi phương thức này, nó chỉ kích hoạt console.log()dòng, nó sẽ không thiết lập thuộc testtính ??
Dưới đây là ứng dụng Angular khởi động nhanh với các thay đổi của tôi.
Cha mẹ
import { Component } from '@angular/core';
import { NotifyComponent } from './notify.component';
@Component({
selector: 'my-app',
template:
`
<button (click)="submit()">Call Child Component Method</button>
`
})
export class AppComponent {
private notify: NotifyComponent;
constructor() {
this.notify = new NotifyComponent();
}
submit(): void {
// execute child component method
notify.callMethod();
}
}
Đứa trẻ
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'notify',
template: '<h3>Notify {{test}}</h3>'
})
export class NotifyComponent implements OnInit {
test:string;
constructor() { }
ngOnInit() { }
callMethod(): void {
console.log('successfully executed.');
this.test = 'Me';
}
}
Tôi cũng có thể đặt thuộc testtính như thế nào?



