我创建了一个子组件,它有一个我想要调用的方法.
当我调用这个方法时它只会触发该console.log()行,它不会设置test属性??
以下是我的更改快速启动Angular应用程序.
亲
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();
}
}
Run Code Online (Sandbox Code Playgroud)
儿童
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'notify',
template: '<h3>Notify {{test}}</h3>'
})
export class NotifyComponent implements OnInit {
test:string;
constructor() …Run Code Online (Sandbox Code Playgroud)