誰でもこのコードの何が問題なのかを見つけてください。イベントを 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 で応答が得られず、デバッガも得られません。