我正在尝试使用 Angular Material 设计,但我一直遇到这个错误
无法绑定(bind)到“mdDatepicker”,因为它不是“input”的已知属性。
我正在关注 this documentation安装 MD。
我已将以下内容导入我的 app.module.ts
/* Material Design */
import { MdDatepickerModule, MdNativeDateModule } from "@angular/material";
并将其添加到@NgModule
@NgModule({
imports:
[
...
BrowserModule,
BrowserAnimationsModule,
HttpModule,
/* Material Design */
MdDatepickerModule,
MdNativeDateModule,
],
在我的组件模板中,我只是复制粘贴了示例代码
<md-form-field>
<input mdInput [mdDatepicker]="picker" placeholder="Choose a date">
<md-datepicker-toggle mdSuffix [for]="picker"></md-datepicker-toggle>
<md-datepicker #picker></md-datepicker>
</md-form-field>
我没有在我的 component.ts 文件中做任何特别的事情
import { Component, Input, Output, EventEmitter } from "@angular/core";
import { TranslationPipe } from "../../../pipes";
@Component({
selector: "date-picker",
templateUrl: "./date-picker.component.html",
styleUrls: ["./date-picker.component.scss"],
})
export class DatePickerComponent {
@Input()
date;
constructor(
private translationPipe: TranslationPipe,
) {
}
}
我被困在这里,找不到任何解决方案。我找到的唯一解决方案是 Can't bind to 'mdDatepicker' since it isn't a known property of 'input' - Angular但如您所见,我实现了它,但对我没有帮助。
我猜我正在查看某些内容,还是我错过了一步?
提前致谢
最佳答案
指令需要在使用它们的模块的 imports: [...]
中列出。
@NgModule({
imports:
[
MdDatepickerModule,
MdNativeDateModule,
]
}
export class SharedModule {
将它们导入 AppModule
只会使它们在 directives: [...]
的 AppModule
中列出的组件中可用,但不会在其他地方使用。
关于angular - 无法绑定(bind)到 'mdDatepicker',因为它不是 'input' 的已知属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46033205/