Run failed with ngc: Error: Can't resolve all parameters for HomePage: (?, ?, ?, ?, ?, ?, ?)


#1

Hello Hello,

I try for the first time to run my ionic app on android but it crash…
It failed with error:
ngc: Error: Can’t resolve all parameters for HomePage: (?, ?, ?, ?, ?, ?, ?).

With ionic serve everything is working… Do you maybe have an idea?

here is my home.ts:

@Component({
  selector: 'page-home',
  template: `
  <ion-content>
  </ion-content>
  `
})
export class HomePage {

  authService : AuthService;
  nav : NavController;
  zone : NgZone;
  userCredentialService : CredentialService;
  usercreds : Object;
  myProfileService : MyProfileService;
  friendsProfileService : FriendsProfileService;
  navParams : NavParams;
  retrieveFriendsFromServer : boolean;

  static get parameters() {
	return [[AuthService],[NavController], [CredentialService], [NgZone], [MyProfileService], [NavParams], [FriendsProfileService]];
  }

  constructor(authservice, navcontroller, userCredential, zone, myProfileService, navParams, friendsProfileService) {
	this.authService = authservice;
	this.nav = navcontroller;
	this.userCredentialService = userCredential;
	this.zone = zone;
	this.navParams = navParams;
	this.myProfileService = myProfileService;
	this.friendsProfileService = friendsProfileService;
	this.usercreds = {
	  email: '',
	  password: ''
	}
  }

my tsconfig

{
  "compilerOptions": {
	"allowSyntheticDefaultImports": true,
	"declaration": true,
	"emitDecoratorMetadata": true,
	"experimentalDecorators": true,
	"lib": [
	  "dom",
	  "es2015"
	],
	"module": "es2015",
	"moduleResolution": "node",
	"target": "es5"
  },
  "exclude": [
	"node_modules"
  ],
  "compileOnSave": false,
  "atom": {
	"rewriteTsconfig": false
  }
}

my package.json

{
  "name": "ionic-hello-world",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
	"build": "ionic-app-scripts build",
	"watch": "ionic-app-scripts watch",
	"serve:before": "watch",
	"emulate:before": "build",
	"deploy:before": "build",
	"build:before": "build",
	"run:before": "build"
  },
  "dependencies": {
	"@ionic/storage": "^1.0.3",
	"es6-shim": "^0.35.1",
	"ionic-angular": "^2.0.0-rc.0",
	"ionic-native": "^2.0.3",
	"ionicons": "^3.0.0",
	"pouchdb": "^6.0.6"
  },
  "devDependencies": {
	"@ionic/app-scripts": "latest",
	"typescript": "^2.0.3"
  },
  "description": "handyou: An Ionic project",
  "cordovaPlugins": [
	"cordova-plugin-device",
	"cordova-plugin-console",
	"cordova-plugin-whitelist",
	"cordova-plugin-splashscreen",
	"cordova-plugin-statusbar",
	"ionic-plugin-keyboard"
  ],
  "cordovaPlatforms": [],
  "config": {
	"ionic_rollup": "./script/rollup.config.js"
  }
}

my config.xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.ionicframework.handyou378891" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
  <name>handyou</name>
  <description>An awesome Ionic/Cordova app.</description>
  <author email="hi@ionicframework" href="http://ionicframework.com/">Ionic Framework Team</author>
  <content src="index.html"/>
  <access origin="*"/>
  <allow-intent href="http://*/*"/>
  <allow-intent href="https://*/*"/>
  <allow-intent href="tel:*"/>
  <allow-intent href="sms:*"/>
  <allow-intent href="mailto:*"/>
  <allow-intent href="geo:*"/>
  <platform name="android">
	<allow-intent href="market:*"/>
  </platform>
  <platform name="ios">
	<allow-intent href="itms:*"/>
	<allow-intent href="itms-apps:*"/>
  </platform>
  <preference name="webviewbounce" value="false"/>
  <preference name="UIWebViewBounce" value="false"/>
  <preference name="DisallowOverscroll" value="true"/>
  <preference name="android-minSdkVersion" value="16"/>
  <preference name="BackupWebStorage" value="none"/>
  <preference name="SplashScreenDelay" value="0"/>
  <preference name="FadeSplashScreen" value="false"/>
  <preference name="FadeSplashScreenDuration" value="0"/>
  <preference name="SplashScreenBackgroundColor" value="0xFFFFFFFF"/>
  <feature name="StatusBar">
	<param name="ios-package" onload="true" value="CDVStatusBar"/>
  </feature>
  <plugin name="cordova-plugin-device" spec="~1.1.3"/>
  <plugin name="cordova-plugin-console" spec="~1.0.4"/>
  <plugin name="cordova-plugin-whitelist" spec="~1.3.0"/>
  <plugin name="cordova-plugin-splashscreen" spec="~4.0.0"/>
  <plugin name="cordova-plugin-statusbar" spec="~2.2.0"/>
  <plugin name="ionic-plugin-keyboard" spec="~2.2.1"/>
</widget>

And finally my app.module.ts

@NgModule({
  declarations: [
	MyApp,
	HomePage,
	CredentSignup,
	ProfileSignup,
	Main,
	FriendsTab,
	MenuTab,
	MyTab,
	NotificationTab,
	Profile,
	Connection,
	Search
  ],
  imports: [
	IonicModule.forRoot(MyApp, {
	  tabsHideOnSubPages : 'true'
	})
  ],
  bootstrap: [IonicApp],
  entryComponents: [
	MyApp,
	HomePage,
	CredentSignup,
	ProfileSignup,
	Main,
	FriendsTab,
	MenuTab,
	MyTab,
	NotificationTab,
	Profile,
	Connection,
	Search,
  ],
  providers: [AuthService, MyProfileServiceDB, HeaderBuilder, UserCredentialServiceDB, MyProfileService, CredentialService, FriendsProfileServiceDB, FriendsProfileService]
})
export class AppModule {}

Does anyone has an idea?

What I really don’t understand is that it is working on serve mode. :frowning:

Thanks a lot!!!


#2

ionic serve does not use ngc since ngc takes a long time :slight_smile:. The issue is more than likely with your Hompage constructor parameters. I would start looking there.

Thanks,
Dan


#3

I looked at it. In fact I removed all the injected values one by one I always got the error
(?, ?, ?, ?) then
(?, ?, ?) then
(?, ?)
etc etc

Once all the injected values where removed it went well for home but failed into the next page with (?) due to nav controller. It seems that no providers are not built :frowning:

All have the @Injectable() from ‘@angular/core’;
Do you have an idea?


#4

I would start by dumping the static parameters getter.


#5

and reading about dependency injection in Angular 2


#6

In fact I know how to use dependency injection in java. My backend is developped in java and is using dependency injection.
To be honnest I started angular2 javascript and typescript 2 weeks ago and I learnt lot of things but I still need to improve.
What I understood
Declaring the providers in the module means that the instance will be injected in the module and be used only by it
If I declare it in the app config it will be shared by all my modules (what I want for all the module declared)
I don’t see the goal of the static get parameter
However when I remove it I get same error on ionic serve. That’s why I decided to keep it. Do you know why ?


#7

Hello,

Thanks a lot. I looked at the doc. It seems that:

static get parameters() {
return [[AuthService],[NavController], [CredentialService], [NgZone], [MyProfileService], [NavParams], [FriendsProfileService]];
}

constructor(authservice, navcontroller, userCredential, zone, myProfileService, navParams, friendsProfileService) {
this.authService = authservice;
this.nav = navcontroller;
this.userCredentialService = userCredential;
this.zone = zone;
this.navParams = navParams;
this.myProfileService = myProfileService;
this.friendsProfileService = friendsProfileService;
this.usercreds = {
email: ‘’,
password: ‘’
}
}

must be replaced by a simple constructor with the type:
constructor(authservice : AuthService, navcontroller : NavController blablabla

Thanks a lot

Best regards

Geoffrey MUSELLI