Angular - two output-events in one component, but only one works

Viewed 2632

I want the child component to emit two different events in it`s parent Component, depending on which button the user clicks. The first one (onSelectedKat) works fine. But the second one (onAllClick) doesn´t work. It has the same structure like the first one, I just changed the names.

I tried to skip all the unnecessary code, so it doesn´t get too confusing.

This is the html code of the child. It has two buttons, which call the two different functions on click. These functions in turn, call the emitter-functions.

<a (click)="selectKat(kategorie.name)" class="btn btn-default btn-kat" role="button">{{kategorie.name}}</a>

<a (click)="clickAll()" class="btn btn-default btn-kat" role="button">Alle</a>

This is the code of the child. Here it gets stuck in the clickAll() function. The console.log works, but everything after that doesn`t.

import { EintraegeComponent } from '../eintraege/eintraege.component';

@Component({
  selector: 'app-kategorien',
  templateUrl: './kategorien.component.html',
  styleUrls: ['./kategorien.component.css'],

})
export class KategorienComponent implements OnInit {

  @Output() onSelectedKat = new EventEmitter<string>();
  @Output() onAllClick = new EventEmitter<any>();

  constructor() {}

  ngOnInit() {}

  selectKat(name: string){
    this.onSelectedKat.emit(name);
  }

  clickAll(){
    console.log("clicked in child works");
    this.onAllClick.emit();
  }

}

And this is the code of the parent. However the onAllClick() in that one is never called.

@Component({
  selector: 'app-eintraege',
  templateUrl: './eintraege.component.html',
  styleUrls: ['./eintraege.component.css']
})
export class EintraegeComponent implements OnInit {

  eintraegegeordnet:boolean;
  toFilter:string;

  constructor() { 
      this.eintraegegeordnet = false;
    }

  ngOnInit() {}

  onAllClick(){
    console.log("Click in parent works");
    this.toFilter = "boo";
    this.eintraegegeordnet = false;
  }

  onSelectedKat(name:string){
    this.eintraegegeordnet = true;
    this.toFilter = name;
  }   

}

Can anyone tell me what I´m doing wrong and why one of them works and the other doesn`t?

1 Answers
Related