2

Hello is there any way to pass two parameters in the output function from child component.

I want to call markQuestion from child component(answer-sheet) with (q_number, value) parameters but it gives me errors.

It works with one parameter.

http://plnkr.co/edit/4WHOT3

<answer-sheet *ngIf="current_question" [questions]="questions" [question] = "current_question" [answer_list]="answers"
    (markQuestion)="markQuestion($event)">
  </answer-sheet>
markQuestion(q_number:number, val:number){
    console.log(q_number , "numaralı soru cevap anahtarından ", val, " olarak isaretlendi" );
    //this.answers[q_number[0]] = {q_number[1]};
  }
export class Answers {
    // @Input() question: Object;
    @Output() markQuestion = new EventEmitter();

    @Input()
    answer_list;

    public question: Object;

    nextQuestionAnsweredButton(q_number,val){
        //There is an error at calling next function -> Supplied parameters do not match ..
        this.markQuestion.next(q_number,val);
    }
}
2
  • Should the Plunker be a fully working example? There seem to be parts missing. Commented Feb 29, 2016 at 11:36
  • Could you post your code? Commented Feb 29, 2016 at 11:39

2 Answers 2

4

You can pass an object

markQuestion.emit({q_number: q_number, value: value});
markQuestion(event:object){
    console.log(event.q_number , "numaralı soru cevap anahtarından ", event.val, " olarak isaretlendi" );
    //this.answers[event.q_number[0]] = {event.q_number[1]};
  }

Otherwise no you can't pass more parameters to an @Output()

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you ! Still it is weird that we cant pass two parameters. Maybe its weird because I don't know the "correct pattern"
You can send one event value. That's a common pattern. You can pack into that event whatever you want though.
how do you consume this event?
1

You can pass an object as argument

this.markQuestion.next({ no: q_number, value val});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.