Witam starams ie wlasnie uczyc angulara czy ktos mogl by mi powiedziec dlaczego ten eventEmitter nie chce dzialac?
Pozdrawiam
import { Component, OnInit, Output, EventEmitter } from '@angular/core';
@Component({
selector: 'app-child',
templateUrl: './child.component.html',
styleUrls: ['./child.component.css']
})
export class ChildComponent implements OnInit {
@Output() buttonSubmitted = new EventEmitter<{message: string}>();
text:string = "";
onSubmit(){
this.buttonSubmitted.emit({message: this.text});
console.log('submitted!')
}
constructor() { }
ngOnInit() {
}
}
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
textArray = [];
onSubmitted(submitData: {message: string}){
console.log(submitData)
this.textArray.push(
submitData.message
);
console.log(this.textArray);
}
}
<input type="text" [(ngModel)]="text" />
<input type="button" value="OK"
(click)="onSubmit()"/>
<app-child (onSubmit)="onSubmitted($event)"></app-child>
<p *ngFor="let item of textArray">{{item}}</p>
{{textArray.length}}