I done Angular 2 application For that i am doing unit testing, but params cant read in that unit tesing
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Params,Router } from '@angular/router';
@Component({
selector: 'moivetwo-app',
template:`<div class="container">
<div class="row" style="text-align:center;">
<div class="col-sm-12">
<h3><span class="label label-info">{{lblName}}</span></h3>
</div>
</div>
<div class="row" >
<div class="col-sm-12">
<input class="form-control input-lg" id="inputlg" type="text" [(ngModel)]='txtValue' [style.border-color]='errColor'>
</div>
</div>
<br/>
<div class="row" style="text-align:center;">
<span class="input-group-btn">
<button class="btn btn-success btn-lg" type="button" id="bot1" (click)='onClick()'>{{ btnTitle }} </button>
</span>
</div>
<br/>
<div class="row" style="text-align:center;">
<span class="input-group-btn" *ngIf='navigated'>
<button class="btn btn-success btn-lg" type="button" (click)='goBack()'>Back </button>
</span>
</div>
</div>`
})
export class EntryPage
{
movieName:string;
btnTitle:string = "Continue";
txtValue:string;
navigated = false;
errColor:string;
lblName:string;
constructor(
private activatedRoute: ActivatedRoute,
private router: Router) {}
goBack(): void {
this.router.navigate(['one']);
}
ngOnInit(): void {
this.movieName = this.activatedRoute.snapshot.params['movie1name'];
if (this.movieName !== undefined) {
this.lblName = "Second Movie";
//this.movieName = params['movie1name'];
this.navigated = true;
console.log(this.movieName);
} else {
this.lblName = "First Movie";
this.navigated = false;
}
}
onClick(){
if(this.txtValue!=undefined && this.txtValue!="")
{
this.errColor="";
if(this.movieName != undefined)
{
let link11 = ['/compare', this.movieName,this.txtValue];
this.router.navigate(link11);
}
else
{
let link = ['/two', this.txtValue];
this.router.navigate(link);
}
} else this.errColor="red";
}
}