Я новичок в 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]
})