2017-08-29 39 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'版本,这个功能更好。 –