【发布时间】:2018-02-12 11:09:13
【问题描述】:
我正在尝试使用 Angular Material 设计,但我一直遇到这个错误
Can't bind to 'mdDatepicker' since it isn't a known property of '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,但正如您所见,我实现了它,但对我没有帮助。
我猜我正在查看某些东西,还是我错过了一步?
提前致谢
【问题讨论】:
-
DatePickerComponent是与上面显示的导入相同的NgModule的一部分吗? -
它是我的
shared.module.ts的组成部分,它是在我的app.module.ts中导入的。显示的代码来自app.module.ts