Skip to content

Updated needed and error on @ViewChild #1

@thomastthai

Description

@thomastthai

In testing this out in my own app, I found some errors that I was able to correct and one I couldn't.

With Ionic 2.1.0-beta.3, the following changes had to be made:

import { Component, Directive, ViewChild } from '@angular/core';
//import { Shrinkage } from 'ionic-shrinkage';
import * as Shrinkage from 'ionic-shrinkage';

@component({
selector: 'page-home',
templateUrl: 'home.html'
//directives: [ Shrinkage ]
})

@directive({
selector: '[Shrinkage]' // <-- [my-dir] because it's an attribute
})

The only error left is this:

11:09:48] typescript: C:/Users/Thomas/ionic2/app/src/pages/home/home.ts, line: 24

        Argument of type 'typeof "C:/Users/Thomas/ionic2/app/node_modules/ionic-shrinkage/dist/index"'
        is not assignable to parameter of type 'string | Function | Type<any>'. Type 'typeof "C:/Users/Thomas/ionic2/app/node_modules/ionic-shrinkage/dist/index"'
        is not assignable to type 'Type<any>'. Property 'apply' is missing in type 'typeof "C:/Users/Thomas/ionic2/app/node_modules/ionic-shrinkage/dist/index"'.
  L23:  // Necessary for the change() method below
  L24:  @ViewChild(Shrinkage) shrinkage;

[11:09:48] transpile failed

export class HomePage {
  conferenceDate = '2047-05-17';

  // We bind content to the shrinkage attribute in the HTML template
  @ViewChild(Content) content: Content;

  // Necessary for the change() method below
  **@ViewChild(Shrinkage) shrinkage;**// <-- line 24

  constructor(public popoverCtrl: PopoverController) { }

  presentPopover(event) {
    let popover = this.popoverCtrl.create(PopoverPage);
    popover.present({ ev: event });
  }

  // If you use Structural Directives to add or remove items in the header,
  // you'll have to call resize() on both content and the shrinkage directive.
  change(e) {
    this.content.resize();
    this.shrinkage.resize();
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions