Typescript 如何获得';左';ngx倒数计时的私有财产?

Typescript 如何获得';左';ngx倒数计时的私有财产?,typescript,timer,properties,angular7,countdown,Typescript,Timer,Properties,Angular7,Countdown,我无法从ngx倒计时中获取“左”属性,这是私有的 我已经读到,你应该宣布财产为公共,但这是一个图书馆只(ngx倒计时),我已经安装 我得到的错误是: src/app/pages/exam levels/exam-level2/exam-level2.component.ts(129,30)中出错:错误TS2341:属性“left”是私有的,只能在类“CountdownComponent”中访问。 src/app/pages/exam levels/exam-level2/exam-level2.

我无法从ngx倒计时中获取“左”属性,这是私有的

我已经读到,你应该宣布财产为公共,但这是一个图书馆只(ngx倒计时),我已经安装

我得到的错误是:

src/app/pages/exam levels/exam-level2/exam-level2.component.ts(129,30)中出错:错误TS2341:属性“left”是私有的,只能在类“CountdownComponent”中访问。 src/app/pages/exam levels/exam-level2/exam-level2.component.ts(130,39):错误TS2341:属性“left”是私有的,只能在类“CountdownComponent”中访问

TS文件

import { Component, OnInit, ViewChild } from '@angular/core';
import { Subscription } from 'rxjs';
import { Router } from '@angular/router';
import { ExamsService } from '@app/services/exams.service';
import { ExamsModel } from '@app/models/exams.model';
import { HostListener } from '@angular/core';
import { ConfirmationModalModel } from '@app/models/confirmation-modal.model';
import { CountdownComponent } from 'ngx-countdown';


@Component({
  selector: 'app-exam-level2',
  templateUrl: './exam-level2.component.html',
  styleUrls: ['./exam-level2.component.scss']
})
export class ExamLevel2Component implements OnInit {

  remainingTime: any;

  seconds = CountdownComponent['left'];

  public questionsListLevel2: Array<ExamsModel>;
  public examLevel2ModalContent: ConfirmationModalModel;

  public timeLeft: CountdownComponent["left"];

  level2QuestionsSet$: Subscription;
  pageTab: string;

  isToggled: boolean;

  status = '';
  @ViewChild('countdown') counter: CountdownComponent;

  resetTimer() {
    this.counter.restart();
    this.counter.stop();
    this.counter.pause();
    this.counter.resume();
  }

  constructor(
    private router: Router,
    private examsService: ExamsService,
  ) {
      this.pageTab = "exam-level2";
    }

  ngOnInit() {
    this.getQuestionsListPart2();
    this.isToggled = false;
  }




  // TIMER
  finishTest() {
    console.log('count down', this.counter);

    setTimeout(() => {
      this.router.navigate(['/exam-level3']);
      }
      , 3000);
  }
  stopTimer () {
    this.counter.pause();
    console.log(this.counter);
    // console.log(this.counter.finished)
    // this.timerService.sayHello();
  }



  onNotify() {
    console.log(this.counter.left);
    this.remainingTime = this.counter.left;

    this.store();
  }

  store(){
    let key = 'Timer';
    localStorage.setItem(key, this.remainingTime);
  }
}
从'@angular/core'导入{Component,OnInit,ViewChild};
从“rxjs”导入{Subscription};
从'@angular/Router'导入{Router};
从'@app/services/exams.service'导入{examservice};
从'@app/models/exames.model'导入{exammodel};
从“@angular/core”导入{HostListener};
从'@app/models/confirmation modal.model'导入{ConfirmationModalModel};
从“ngx倒计时”导入{CountdownComponent};
@组成部分({
选择器:“app-exam-level2”,
templateUrl:'./exam-level2.component.html',
样式URL:['./exam-level2.component.scss']
})
导出类Examlevel2组件实现OnInit{
剩余时间:任意;
秒=倒计时组件[‘左’];
公共问题2级:数组;
公共示例2模块内容:确认模块模型;
公共时间限制:倒计时组件[“左”];
level2QuestionsSet$:订阅;
页面选项卡:字符串;
isToggled:布尔型;
状态='';
@ViewChild(“倒计时”)计数器:倒计时组件;
重置计时器(){
this.counter.restart();
这个.counter.stop();
this.counter.pause();
这个.counter.resume();
}
建造师(
专用路由器:路由器,
私人ExamService:ExamService,
) {
this.pageTab=“考试级别2”;
}
恩戈尼尼特(){
this.getQuestionsListPart2();
this.isToggled=false;
}
//计时器
完成测试(){
console.log('倒计时',此计数器);
设置超时(()=>{
this.router.navigate(['/exam-level3']);
}
, 3000);
}
停止计时器(){
this.counter.pause();
console.log(this.counter);
//console.log(this.counter.finished)
//this.timerService.sayHello();
}
onNotify(){
console.log(此计数器位于左侧);
this.remainingTime=this.counter.left;
这个。store();
}
存储(){
让键='计时器';
setItem(key,this.remainingTime);
}
}

模板

 <!-- TIMER START -->
        <div class="timer-container">
          <countdown #countdown [config]="{leftTime: 1800, notify: [ 1795 ]}" (finished)="finishTest()" (notify)="onNotify($event)">$!m!:$!s!</countdown>
          <button (click)="stopTimer()" class="btn btn-link btn-sm">STOP</button>
          <button (click)="store()" class="btn btn-link btn-sm">STORE</button>
        </div>
        <!-- TIMER END -->

$!m!:$!s
停止
贮藏

在我的情况下,您可以通过事件访问

HTML:


打字稿:

onEvent($event): void {
    let timeLeft = $event.left;
}
对于notify事件,它必须相同。通过这种方式,您可以在不出错的情况下访问私有版

新建编辑:

编译时显示

但当我尝试记录它时,它显示了值

在HTML中,您可以像这样访问

<countdown #cnt [config]="{leftTime: 360 * 10}">$!m!:$!s!</countdown>
  <br>
  {{cnt.left}}
$!m!:$!s

{{cnt.left}