Error on constructor parameter


#1

Good morning,

I have created a new page and I have added this code, but when I compile it , ionic gives me an error on constructor parameter.

What is the problem ?

The script file is .js:

import {Component} from '@angular/core';
import {Platform} from 'ionic-angular'

@Component({
  templateUrl: 'build/pages/search/search.html',
})
export class SearchPage {
  static get parameters() {
    return [[Platform]];
  }

  constructor(platform: Platform) {   <---- Error
    this.platform = platform;
  }
}

thanks in advance for your help.


#2

If your file is JavaScript and not TypeScript then it should be:

constructor(platform) {


#3

Good morning,

thank you for your help. I’ve added NavController and if I print it with console.log(), the value is “undefined”… why ?

import {Component} from '@angular/core';
import {Platform,NavController} from 'ionic-angular'

@Component({
  templateUrl: 'build/pages/search/search.html',
})
export class SearchPage {
  static get parameters() {
    return [[Platform, NavController]];
  }

  constructor(platform, navController) {
    this.platform = platform;
    console.log(this.platform.is('ios'));
    console.log(navController);
  }
}

#4
static get parameters() {
    return [[Platform, NavController]];
}

should be:

static get parameters() {
    return [[Platform], [NavController]];
}

#5

Good morning,

Really thank you very much!


#6

if typeScript could set an example to inject Platform and NavController together.