简体   繁体   中英

Angular 2 RC 5 - Can't bind to '…' since it isn't a known property of '…'

Since the update to Angular 2 RC 5 I issue some problems. I have 3 components (battery, signal and maps) that are used in another component. These 3 components are declared in one module: the helpers module. Here is the code:

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

The battery component looks like this:

@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';
        }
    }
}

But when I try to use the as-my-battery with the input level, I get this error:

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

Has someone else these issues, and eventually a solution for this problem?

I also found this topic, but that wasn't an answer for me: Can't bind to 'data' since it isn't a known property of 'teach-data'

And at last, this is the bootstrap of my app:

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

The battery component needs to be used in the LijstComponent, declaration of the module:

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

The LijstComponent:

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

export class LijstComponent {
...
}

And a snippet of the html (data is a *ngFor that is looping):

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

I founded the solution, the problem lies with the uglify option of gulp. When setting the mangle option to false (in config.js), the app build and the error has gone!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM