Angular 2 : Can't bind to 'ngPluralCase' since it isn't a known property of 'x'

标签 angular typescript pluralize

首先,这个问题不是重复的,大多数像“无法绑定(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'.

ma​​in.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/

相关文章:

css - 如何用 ngStyle 覆盖子元素样式

javascript - 正则表达式/JavaScript : Split string to separate lines by max characters per line with looking n chars backwards for a possible whitespace?

typescript - 访问联合类型中的属性

ruby-on-rails - 测试 Ruby on Rails 中的单词是单数还是复数

qt - QObject::tr() 的复数重载是否将 %n 转换为本地数字?

angular - Angular 中的 bootstrap 函数是做什么的

Angular2 组件选择器 : array like '[ui-components]'

angular - 如何使用 Angular 2 为不同的环境加载不同的全局 css 样式

node.js - NodeJS Azure Functions - 从同一存储库的不同文件夹嵌套级别导出函数

ruby-on-rails - 在 rails3 中覆盖模型名称的默认复数形式