0
Guys, I really need your help. According to this tutorial tutorial I need a custom component that displays the following error:
"Can’t bind to 'expandHeight' Since it isn’t a known Property of 'Expandable'."
when I run my app.
In my case "home.html" is "rate-fire.html". Here it is:
<ion-list>
  <button detail-none (click)="expandItem(item)" ion-item *ngFor="let item of items">
    <ion-thumbnail item-start>
      <img src="assets/imgs/bolacha.png">
    </ion-thumbnail>
    <h2>My Neighbor Totoro</h2>
    <p>Hayao Miyazaki • 1988</p>
    **<expandable** [expandHeight]="itemExpandHeight" [expanded]="item.expanded">
        Hello people
    **</expandable>**
    <button ion-button clear item-end>View</button>
  </button>
</ion-list>
My rate-fire.ts:
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
/**
 * Generated class for the TaxaIncendioPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */
@IonicPage()
@Component({
  selector: 'page-taxa-incendio',
  templateUrl: 'taxa-incendio.html',
})
export class TaxaIncendioPage {
  items: any = [];
  itemExpandHeight: number = 100;
  constructor(public navCtrl: NavController, public navParams: NavParams) {
    this.items = [
      {expanded: false},
      {expanded: false},
      {expanded: false},
      {expanded: false},
      {expanded: false},
      {expanded: false},
      {expanded: false},
      {expanded: false},
      {expanded: false}
    ];
  }
  expandItem(item){
    this.items.map((listItem) => {
        if(item == listItem){
            listItem.expanded = !listItem.expanded;
        } else {
            listItem.expanded = false;
        }
        return listItem;
    });
  }
  ionViewDidLoad() {
    console.log('ionViewDidLoad TaxaIncendioPage');
  }
  exibir(item)
  { 
    item.styleClass = (Number(item.styleClass) == 1)?0:1;
  }
}
My rate of fire.scss:
    .ios, .md{
    page-taxa-incendio {
        button{
            align-items: baseline;
        }
    }
}
NOTE: I circled the error with ** **.
My expendable.ts:
import { Component, Input, ViewChild, ElementRef, Renderer } from '@angular/core';
/**
 * Generated class for the ExpendableComponent component.
 *
 * See https://angular.io/api/core/Component for more info on Angular
 * Components.
 */
@Component({
  selector: 'expendable',
  templateUrl: 'expendable.html'
})
export class ExpendableComponent {
  text: string;
  @ViewChild('expandWrapper', {read: ElementRef}) expandWrapper;
  @Input('expanded') expanded;
  @Input('expandHeight') expandHeight;
  constructor(public renderer: Renderer) {
    console.log('Hello ExpendableComponent Component');
    this.text = 'Hello World';
  }
  ngAfterViewInit(){
    this.renderer.setElementStyle(this.expandWrapper.nativeElement, 'height', this.expandHeight + 'px');   
  }
}
My Expandable.html:
<!-- Generated template for the ExpendableComponent component -->
<div #expandWrapper class='expand-wrapper' [class.collapsed]="!expanded">
  <ng-content></ng-content>
</div>
My Expandable.scss:
expandable {
    .expand-wrapper {
        transition: 0.2s linear;
    }  
    .collapsed {
        height: 0 !important;
    }
}
The same error persists. Vscode still leaves it red, as if it did not recognize it as a tag
– Wanderley Drumond
vc also compiled to see if the error persists at runtime?
– jraspante
Yes, I took that test and the same mistake persists
– Wanderley Drumond
try setting a type for @Input('Expanded') Expanded; and @Input('expandHeight') expandHeight;
– jraspante
I’ve already declared them separately there in the expendable.ts file.
– Wanderley Drumond
Yes, I say to define a type number, any, string...
– jraspante
Did not work. Error persists
– Wanderley Drumond
could put your code in stackblitz?
– jraspante
I never used this tool, but from what I understand I will only upload the src folder, right? https://stackblitz.com/edit/ionic-38qk93
– Wanderley Drumond
yes, you can also upload only the necessary components and remember to import the components in app.module.ts
– jraspante
I adapted your code, it worked.
– jraspante
Voce added Expendablecomponent to its declarations and entrycomponents in app.module.ts?
– jraspante
take a look. https://stackblitz.com/edit/ionic-b4wmbg
– jraspante
Expendablecomponent serves to make a menu like accordion. The one who sent me the menu cannot have the power to retract and expand. This is exactly what happens when I comment on the <expendable> tag. You can see?
– Wanderley Drumond
I didn’t get to include the CSS files in stackblitz. But the error you quoted in the question apparently got fixed
– jraspante
Indeed it was. Thank you very much for your help and for taking the time to do so.
– Wanderley Drumond
I’m glad the bug was fixed. I wish I could spend a little more time helping you with the accordion list, but now I can’t. I didn’t get to include the.scss file in the stackblitz, it may be that they have an effect. If you can’t, open a new topic and other members can help you with this issue.
– jraspante