angularjs – Angular 2 RC 5 – 无法绑定到’…’,因为它不是’…’的已知属性

前端之家收集整理的这篇文章主要介绍了angularjs – Angular 2 RC 5 – 无法绑定到’…’,因为它不是’…’的已知属性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
自Angular 2 RC 5更新后,我发布了一些问题.我有3个组件(电池,信号和地图),用于另一个组件.这三个组件在一个模块中声明:helpers模块.
这是代码

@NgModule({
    declarations: [
        SignalComponent,BatteryComponent,MapsComponent
    ],imports : [
        BrowserModule,FormsModule
    ],exports: [
        SignalComponent,MapsComponent
    ]
})
export class HelpersModule {
}

电池组件如下所示:

@Component({
    selector: 'as-my-battery',template: `
        <i class="fa fa-{{icon}}" aria-hidden="true"></i>
        `
})

export class BatteryComponent {
    @Input() level: number;
    @Output() icon: string;
    // constructor() { }

    ngOnInit () {
        if (this.level < 5) {
            this.icon = 'battery-empty';
        } else if (this.level >= 5 && this.level < 25) {
            this.icon = 'battery-quarter';
        } else if (this.level >= 25 && this.level < 50) {
            this.icon = 'battery-half';
        } else if (this.level >= 50 && this.level < 75) {
            this.icon = 'battery-three-quarters';
        } else {
            this.icon = 'battery-full';
        }
    }
}

但是当我尝试使用输入级别的as-my-battery时,我收到此错误

Error: Uncaught (in promise): Template parse errors:
Can't bind to 'level' since it isn't a known property of 'as-my-battery'.
1. If 'as-my-battery' is an Angular component and it has 'level' input,then verify that it is part of this module.
2. If 'as-my-battery' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schema' of this component to suppress this message.
 (""checkBox" name={{data.name}} value={{data.name}}> {{data.name}}
                    <as-my-battery [ERROR ->][level]='data.battery'></as-my-battery>
                    <as-my-signal [level]='data.signal'></as-"): a@19:35

有其他人这些问题,并最终解决这个问题?

我也找到了这个话题,但这不是我的答案:Can’t bind to ‘data’ since it isn’t a known property of ‘teach-data’

最后,这是我的应用程序的引导程序:

@NgModule({
    declarations: [
        AppComponent
    ],imports: [
        NavbarModule,LoginModule,HelpersModule,KaartModule,LijstModule,LogsModule,InstellingenModule,StatistiekenModule,routing
    ],providers: [ APP_PROVIDERS,appRoutingProviders ],bootstrap: [ AppComponent ]
})
export class AppModule {
}

电池组件需要在LijstComponent中使用,模块声明:

@NgModule({
    declarations: [
        LijstComponent
    ],imports: [
        BrowserModule,HelpersModule
    ],exports: [
        LijstComponent
    ]
})
export class LijstModule {
}

LijstComponent:

@Component({
    selector: 'as-lijst',providers: [DataService,MarkerService,AlertService],templateUrl: 'app/lijst/lijst.html',})

export class LijstComponent {
...
}

和html的片段(数据是循环的* ngFor):

<as-my-battery [level]='data.battery'></as-my-battery>

解决方法

我创建了解决方案,问题在于gulp的uglify选项.将mangle选项设置为false(在config.js中)时,应用程序构建和错误已经消失!

猜你在找的Angularjs相关文章