У меня есть два компонента, один - home.component, а другой - loading.component (экран загрузки).На экране загрузки есть обратный отсчет, и после обратного отсчета он что-то делает.Что мне нужно сделать, это сделать экран загрузки способным к произвольной длине обратного отсчета.Я пытался использовать EventEmiter, но он не работает.
home.component.html:
<a (click)="applyChanges()" class="green" style="margin-left: 8px; cursor: pointer"><i style="margin-right: 5px;"class="fa fa-check"></i>Apply changes now</a>
home.component.ts
@Output() loadingScreenStart: EventEmitter<any> = new EventEmitter();
applyChanges(){
this.dashboard.applyChanges().catch(
err => {
console.log("There was an error: "+err.status);
console.log("There was an error: "+err.statusText);
//this.handleError(err);
return Observable.throw(err);
}
)
.subscribe(
data => {
this.loadingScreenStart.emit(34);
this.router.navigate(['/loading']);
}
);
} загрузка.component.html
<div class="container container-table" (loadingScreenStarted)="onScreenStart($event)">
<div class="row vertical-10p">
<div class="container">
<img src="../../assets/img/LoginLogo.png" class="center-block logo">
<img style="width: 15em" src="../../assets/img/gears.svg" class="center-block ">
<div class="text-center col-sm-6 col-sm-offset-3">
<h1>Changes are taking place</h1>
<h4>You will be redirected in {{timeLeft}} seconds</h4>
</div>
</div>
</div>
loading.component.ts
import { Component, OnInit, Input } from '@angular/core';
import { AuthGuard } from '../guard/auth.guard';
import { Title } from '@angular/platform-browser';
@Component({
selector: 'app-loading',
templateUrl: './loading.component.html',
styleUrls: ['./loading.component.css']
})
export class LoadingComponent implements OnInit {
public timeLeft;
public intervalId;
constructor(public titleService: Title, public guard: AuthGuard) { }
onScreenStart(length) {
this.timeLeft = length;
console.log(length);
}
ngOnInit() {
this.titleService.setTitle("Loading... | something);
this.startCounter();
localStorage.removeItem('statusInfo');
}
startCounter() {
this.intervalId = setInterval(() => {
if (this.timeLeft == 1) {
clearInterval(this.interValId);
}
this.timeLeft--;
}, 1000)
}
}