首先,这个问题不是重复的,大多数像“无法绑定(bind)到‘x’...”这样的问题的答案都是关于未导入的模块,我已经导入了正确的一个。
我正在关注 angular.io 关于 ngPlural
的文档和 ngPluralCase
指令:
<some-element [ngPlural]="value"> <ng-container *ngPluralCase="'=0'">...</ng-container> <ng-container *ngPluralCase="'other'">...</ng-container> </some-element>
(...)
exported from @angular/common/index, defined in @angular/common/src/directives/ng_plural.ts
当我尝试运行此代码时,出现错误 (see it in plnkr) :
Can't bind to 'ngPluralCase' since it isn't a known property of 'ng-container'.
main.ts :
import { platformBrowserDynamic } from "@angular/platform-browser-dynamic";
import { Component, NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
@Component({
selector: "my-app",
template:`
<div [ngPlural]="1">
<ng-container *ngPluralCase="'=0'">...</ng-container>
<ng-container *ngPluralCase="'other'">...</ng-container>
</div>
`,
styles: []
})
class AppComponent {
}
@NgModule({
imports: [
BrowserModule
],
declarations: [AppComponent],
exports: [AppComponent],
bootstrap: [AppComponent]
})
class AppModule { }
platformBrowserDynamic().bootstrapModule(AppModule);
我在我的 AppModule
中导入了 BrowserModule
(导出 CommonModule
,但我也尝试直接导入 CommonModule
) ,正如您所看到的,错误是关于 ngPluralCase
而不是 ngPlural
,后者在同一模块中并且使用没有问题...
所以我的问题是:
有人知道这里发生了什么吗?这是与这些指令的“实验”状态相关的错误还是我遗漏了什么?
PS:我使用的是 angular v2.1.0
最佳答案
目前我打开了一个 issue on the Github repo ,因为它看起来真的坏了....
编辑 这是answer that I got来 self 的 Github 问题:
The problem here is actually that the NgPluralCase directive uses an @Attribute injection and because
ng-container
are virtual nodes, attributes can not be retrieved on them.You have to use a
<template>
tag in this case, the docs will be fixed as part of a pending PR.
关于 Angular 2 : Can't bind to 'ngPluralCase' since it isn't a known property of 'x' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40106850/