1
I’m a beginner in Angular 2 and need to open a page (Component) and pass an object to it. Routes are mapped and in function calcularResultado
, need to send the questoes object to the Component defined on 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");
}
}