谁能发现这段代码有什么问题,我没有将事件返回给 appcomponent
test1.component.html
<input type="text" [(ngModel)]="mytext1" >
<button
id="clicked"
name="Click Me"
class="button"
(click)="returnData();">
Click Me!
</button>
test1.component.ts
import {
Component,
OnInit,
Input,
Output,
EventEmitter
} from '@angular/core';
@Component({
selector: 'app-test1',
templateUrl: './test1.component.html',
styleUrls: ['./test1.component.css']
})
export class Test1Component implements OnInit {
constructor() {}
@Input() mytext1: string;
@Output() dataEmit: EventEmitter < string > = new EventEmitter < string > ();;
ngOnInit() {}
changeText1($event) {
this.mytext1 = $event;
}
returnData() {
console.log("button clicked");
this.dataEmit.emit(this.mytext1);
}
}
app.component.html
<div style="text-align:center">
<h1>
Welcome to {{ title }}!
</h1>
<app-test1 [mytext1]="childmessage" (returnData)="getTest1Data($event)"></app-test1>
{{testText2}}
</div>
app.component.ts
import {
Component,
Input,
OnInit
} from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
title = 'AngularDemo';
public testText2: string = "from parent";
childmessage: string = "I am passed from Parent to child component";
getToggle($event) {
this.testText2 = $event;
}
ngOnInit() {
}
}
我没有得到关于 app.component.ts 的响应,也没有得到调试器。