2017-08-29 94 views
0

我使用angular-cli生成我的項目,版本爲1.0.0-beta.28.3
我在終端編寫命令ng lint,並得到大量的錯誤:聲明前使用的變量

enter image description here

我沒有爲什麼我得到運行ng lint後該金額的錯誤任何想法。

下面的代碼machines.component.ts

import { Component, OnDestroy, OnInit } from '@angular/core'; 
import { Response } from '@angular/http'; 
import { Observable } from 'rxjs/Observable'; 
import { DialogService } from 'ng2-bootstrap-modal'; 

import { ModalComponent } from '../modal/modal.component'; 
import { MachineService } from '../services/machine.service'; 
import { Machine } from '../models/machine.model'; 
import { BoxService } from '../services/box.service'; 
import { Box } from '../models/box.model'; 
import { AppConfig } from '../app.config'; 

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

    private display: boolean; 
    private alive: boolean; 
    private timer: Observable<number>; 
    machines: Machine []; 
    box: Box; 

    constructor(
    private dialogService: DialogService, 
    private boxService: BoxService, 
    private machineService: MachineService, 
    private appConfig: AppConfig) { 
    this.display = false; 
    this.alive = true; 
    this.timer = Observable.timer(0, this.appConfig.interval_requests); 
    } 

    ngOnInit() { 
    this.timer 
     .takeWhile(() => this.alive) 
     .subscribe(() => { 
     this.machineService.getStatesMachines().subscribe(
      (res: Response) => { 
      this.machines = res.json(); 

      if (!this.display) { 
       this.display = true; 
      } 
      } 
     ); 
     } 
    ); 
    } 

    ngOnDestroy() { 
    this.alive = false; 
    } 

    getBox(device_name: string) { 
    this.boxService.getBox(device_name).subscribe(
     (res: Response) => { 
     const box = res.json(); 
     this.box = box; 

     this.dialogService.addDialog(ModalComponent, { 
      device_name: this.box.device_name + '`s info', 
      name: this.box.name, 
      timestamp: this.box.timestamp, 
      ip_address: this.box.ip_address 
     }, {closeByClickingOutside: true}); 
     } 
    ); 
    } 

} 

當生成項目,我並沒有改變tslint.json任何屬性。默認,"no-use-before-declare": true

我在Github和Stackoverflow搜索了答案,但沒有找到。也許,如果到目前爲止沒有找到,我就會嚴重地搜查它。
請幫幫我。

+3

你爲什麼不通過升級開始之前到ng-cli的最新穩定版本以及隨附的tslint版本。自從您使用的過時beta版本以來,可能會出現很多錯誤和改進。 –

+0

我更新了'angular-cli'。 –

回答

3

可以設置"no-use-before-declare": false

這條規則主要是有用的使用var關鍵字時 - 編譯器會檢測是否使用了letconst變量聲明它

+0

我曾經想設置''no-use-before-declare':false',但是最後,我決定如果我更新'angular-cli'版本,這個功能更好。 –