Angular 错误TS7028:未使用的标签

Angular 错误TS7028:未使用的标签,angular,Angular,在angular4中,我得到以下误差。请解决任何问题。提前谢谢 新的cmp组件。ts:: import { Component, OnInit } from '@angular/core'; // here angular/core is imported . @Component({ selector: 'app-new-cmp', templateUrl: './new-cmp.component.html', styleUrls: ['./new-cmp.component.

在angular4中,我得到以下误差。请解决任何问题。提前谢谢

新的cmp组件。ts:

import { Component, OnInit } from '@angular/core'; // here angular/core is imported .

@Component({
  selector: 'app-new-cmp',
  templateUrl: './new-cmp.component.html',
  styleUrls: ['./new-cmp.component.css']
})
export class NewCmpComponent implements OnInit {

  constructor() {
       newcomponent: 'Entered in new component created';
  }
  ngOnInit() {    
  }

}
错误:
错误:在src/app/new-cmp/new-cmp.component.ts中:错误TS7028:未使用的标签。

我猜您正在使用TSLint。发生此错误的原因是您声明了一个变量(未在其前面使用
const
let
var
),并且从未使用过它。它也是以错误的方式声明的。它不应该是
newcomponent:“Entered in new component created”
,而是(如果它是常量)将其声明为

const newcomponent='Entered in new component created'


请注意,在声明它时使用冒号(:)而不是等号(=)。如果使用冒号,则应指定类型(例如
constmylabel:string;

首先声明变量,然后使用它

import { Component, OnInit } from '@angular/core'; // here angular/core is imported .

@Component({
    selector: 'app-new-cmp',
    templateUrl: './new-cmp.component.html',
    styleUrls: ['./new-cmp.component.css']
})
export class NewCmpComponent implements OnInit {

    const newcomponent = 'Entered in new component created';

    public newcomponent2: string;

    constructor() {
        this.newcomponent2 = 'Entered in new component created';
    }
    ngOnInit() {    
    }

}

现在,我在构造函数方法的外面声明变量“NewcomComponent”。 这个现在很好用

import { Component, OnInit } from '@angular/core'; // here angular/core is imported .

@Component({
  selector: 'app-new-cmp',
  templateUrl: './new-cmp.component.html',
  styleUrls: ['./new-cmp.component.css']
})

export class NewCmpComponent implements OnInit {

  **newcomponent: 'Entered in new component created';**

  constructor() {       
  }
  ngOnInit() {    
  }

}

我在声明行遇到了相同的错误:

declarations:[AddFlightPage]
我刚刚用let声明了它,它成功了

let declarations:[AddFlightPage]

NewcomComponent:“在创建的新组件中输入”;从构造函数中删除此行,然后选中并在构造函数外部声明NewcomComponent,然后在构造函数内部声明this.NewcomComponent='Entered in new component created'。