![](/img/trans.png)
[英]Angular2 RC5: Can't bind to 'Property X' since it isn't a known property of 'Child Component'
[英]Angular2 : Can't bind to 'ngPluralCase' since it isn't a known property of 'x'
首先,這個問題不是重復的,大多數諸如“無法綁定到'x'...”之類的問題的答案都是關於未導入的模塊的,我已經導入了正確的模塊。
我正在關注有關ngPlural
和ngPluralCase
指令的angular.io文檔:
<some-element [ngPlural]="value"> <ng-container *ngPluralCase="'=0'">...</ng-container> <ng-container *ngPluralCase="'other'">...</ng-container> </some-element>
(......)
從@ angular / common / index導出,在@ angular / common / src / directives / ng_plural.ts中定義
當我嘗試運行此代碼時,出現錯誤(請在plnkr中查看) :
無法綁定到“ ngPluralCase”,因為它不是“ 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);
我進口BrowserModule
(其中出口CommonModule
,但我也試過進口CommonModule
直接)在我AppModule
,正如你所看到的,誤差約為ngPluralCase
而不是ngPlural
這是同一個模塊和沒有問題使用...
所以我的問題是:
有人知道這里發生了什么嗎? 是與這些指令的“實驗”狀態有關的錯誤,還是我缺少某些東西?
PS :我正在使用angular v2.1.0
目前,我在Github存儲庫上打開了一個問題 ,因為它似乎真的壞了。
這里的問題實際上是NgPluralCase指令使用@Attribute注入,並且由於
ng-container
是虛擬節點,因此無法在其上檢索屬性。在這種情況下,您必須使用
<template>
標簽,這些文檔將作為待定PR的一部分進行修復。
答案是angular.io現在已經過時,至少是NgPlural的示例。
以下示例適用於v2.4.4:
<some-element [ngPlural]="value">
<template ngPluralCase="=0">there is nothing</template>
<template ngPluralCase="=1">there is one</template>
<template ngPluralCase="few">there are a few</template>
</some-element>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.