Angular 2 - 错误“属性'iconName'在类型'StateParams'上不存在

Angular 2 - 错误“属性'iconName'在类型'StateParams'上不存在

问题描述:

我正在使用ui-router-ng2来处理我的web应用程序中的路由我当前正在发送一个字符串(iconName)作为参数检视另一Angular 2 - 错误“属性'iconName'在类型'StateParams'上不存在

这里是我的icon.component.ts

import { Component } from '@angular/core'; 
import { StateService } from 'ui-router-ng2'; 

@Component({ 
    selector: 'icon', 
    templateUrl: 'icon.html', 
}) 
export class IconComponent { 
    StateService: StateService; 
    iconName: StateService; 


    constructor(stateService: StateService) { 
     this.StateService = stateService; 

     this.iconName = this.StateService.params.iconName; 
    } 
} 

此代码行: this.iconName = this.StateService.params.iconName;被抛出以下错误:Property 'iconName' does not exist on type 'StateParams'.

这可能是因为我需要初始化icoName和assi它的参数?我只是不知道该怎么去解决这个错误

看来我错误地使用了params。这是该行应如何看起来像:

this.iconName = this.StateService.params['iconName'];

以此为参考 TypeScript Build Error : Property does not exist on type 'IStateParamsService'