【发布时间】:2019-04-14 15:54:33
【问题描述】:
我是 Ionic 的新手,我想创建一个自定义列表视图,其中包含以下链接:https://www.joshmorony.com/creating-an-accordion-list-in-ionic/ 之后的可扩展项目。
问题是我的自定义组件从未被识别,我尝试了很多东西但没有任何效果......我使用的是 Ionic 4,他们没有在他们的文档中谈论组件生成。
错误是:
Error: Template parse errors:
'expandable' is not a known element:
1. If 'expandable' is an Angular component, then verify that it is part of this module.
2. To allow any element add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.
expandable.component.html:
<div #expandWrapper class='expand-wrapper' [class.collapsed]="!expanded">
<ng-content></ng-content>
</div>
expandable.component.ts:
import { Component, Input, ViewChild, ElementRef, Renderer } from '@angular/core';
@Component({
selector: 'app-expandable',
templateUrl: './expandable.component.html',
styleUrls: ['./expandable.component.scss']
})
export class ExpandableComponent {
@ViewChild('expandWrapper', {read: ElementRef}) expandWrapper;
@Input('expanded') expanded;
@Input('expandHeight') expandHeight;
constructor(public renderer: Renderer) {
}
ngAfterViewInit(){
this.renderer.setElementStyle(this.expandWrapper.nativeElement, 'height', this.expandHeight + 'px');
}
}
这是我尝试使用它的方式:
<expandable [expandHeight]="itemExpandHeight" [expanded]="pet.expanded">
Hello people
</expandable>
最后,我的 app.module.ts :
@NgModule({
declarations: [AppComponent, ExpandableComponent],
entryComponents: [],
imports: [
BrowserModule,
IonicModule.forRoot(),
AppRoutingModule,
IonicStorageModule.forRoot()
],
providers: [
StatusBar,
SplashScreen,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
DatabaseService,
PetService,
SQLite
],
bootstrap: [AppComponent]
})
【问题讨论】:
-
我也有同样的问题。你找到什么了吗?
-
请看我解决的答案
标签: angular typescript ionic-framework ionic4