Component problem called expendable in Ionic 3

Asked

Viewed 108 times

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;
    }

}

Error screen html

Error screen app

1 answer

1


In his home.html you called by the Exp selectortondable, but in their expendable.ts vc declared the selector as Expandndable.

Switch to

<expendable [expandHeight]="itemExpandHeight" [expanded]="item.expanded">
        Hello people
</expendable>
  • The same error persists. Vscode still leaves it red, as if it did not recognize it as a tag

  • 1

    vc also compiled to see if the error persists at runtime?

  • Yes, I took that test and the same mistake persists

  • 1

    try setting a type for @Input('Expanded') Expanded; and @Input('expandHeight') expandHeight;

  • I’ve already declared them separately there in the expendable.ts file.

  • 1

    Yes, I say to define a type number, any, string...

  • Did not work. Error persists

  • 1

    could put your code in stackblitz?

  • I never used this tool, but from what I understand I will only upload the src folder, right? https://stackblitz.com/edit/ionic-38qk93

  • 1

    yes, you can also upload only the necessary components and remember to import the components in app.module.ts

  • 1

    I adapted your code, it worked.

  • 1

    Voce added Expendablecomponent to its declarations and entrycomponents in app.module.ts?

  • 1

    take a look. https://stackblitz.com/edit/ionic-b4wmbg

  • 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?

  • 1

    I didn’t get to include the CSS files in stackblitz. But the error you quoted in the question apparently got fixed

  • Indeed it was. Thank you very much for your help and for taking the time to do so.

  • 1

    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.

Show 12 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.