I am a beginner in Angular 2 and need to open a page (Component) and pass an object to it. The routes are mapped and in the calcularResultado
function, I need to send the objects to the component defined in the "/ result" route
import { Component, OnInit } from '@angular/core';
import { QuestoesService } from "./questoes.service";
import { Router, NavigationExtras } from "@angular/router";
@Component({
selector: 'app-questoes',
templateUrl: './questoes.component.html',
styleUrls: ['./questoes.component.css']
})
export class QuestoesComponent implements OnInit {
questoes:any = new QuestoesService().getQuestoes();
questaoSelecionada: any;
questaoSelecionadaIndex: number = 0;
router:Router;
constructor(router: Router) {
this.router = router;
this.questaoSelecionada = this.questoes[0];
}
ngOnInit() {
}
avancar(){
this.questaoSelecionadaIndex++;
this.questaoSelecionada = this.questoes[this.questaoSelecionadaIndex];
}
voltar(){
this.questaoSelecionadaIndex--;
this.questaoSelecionada = this.questoes[this.questaoSelecionadaIndex];
}
calcularResultado(questoes){
this.router.navigateByUrl("/resultado");
}
}