我在Material Angular上还很新,我正在尝试向项目中添加一些组件。
现在,我正在尝试将expansion-panel组件示例添加到对话框中,但是该组件无法正常工作,我正在努力工作,并且我不知道为什么。
我正在研究 Angular 5.2.0 和 Material Angular 5.2.5 。
我已经将模块导入了main.ts
import {MatExpansionModule} from '@angular/material/expansion';
我创建了expand-overview.component.html
<mat-accordion>
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-panel-title>
Personal data
</mat-panel-title>
<mat-panel-description>
Type your name and age
</mat-panel-description>
</mat-expansion-panel-header>
<mat-form-field>
<input matInput placeholder="First name">
</mat-form-field>
<mat-form-field>
<input matInput placeholder="Age">
</mat-form-field>
</mat-expansion-panel>
<mat-expansion-panel (opened)="panelOpenState = true"
(closed)="panelOpenState = false">
<mat-expansion-panel-header>
<mat-panel-title>
Self aware panel
</mat-panel-title>
<mat-panel-description>
Currently I am {{panelOpenState ? 'open' : 'closed'}}
</mat-panel-description>
</mat-expansion-panel-header>
<p>I'm visible because I am open</p>
</mat-expansion-panel>
</mat-accordion>
我创建了expand-overview.component.ts
import {Component} from '@angular/core';
@Component({
selector: 'jhi-expansion-overview',
templateUrl: 'expansion-overview.component.html',
})
export class ExpansionOverviewComponent {
panelOpenState: boolean;
}
最后,我在对话框中添加了选择器 jhi-expansion-overview
恢复
<div class="modal-header"></div>
<div class="modal-body">
<jhi-alert-error></jhi-alert-error>
<jhi-expansion-overview></jhi-expansion-overview>
</div>
<div class="modal-footer">
<button type="button" class="btn custom custom-btn-secondary" data-dismiss="modal" (click)="clear()">
<span jhiTranslate="entity.action.save">Save</span>
</button>
<button type="button" class="btn custom custom-btn-secondary" data-dismiss="modal" (click)="clear()">
<span jhiTranslate="entity.action.cancel">Cancel</span>
</button>
</div>
</form>
最后,我得到了这个结果:
我已经在项目中使用了其他组件,而这是我遇到问题的唯一组件。
有人知道为什么我得到这个结果或我做错了什么吗?
谢谢
答案 0 :(得分:1)
我只是在main.ts中发现错误,缺少添加:
exports: [MatExpansionModule]
现在正在工作。
答案 1 :(得分:0)
转到 app.modules.js 并更改导入:
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
和
imports: [
BrowserAnimationsModule,
...,
]