HTTP post error with Inject error message


#1

Hi all,

I have error when try to run the ionic serve , it always comes out with the error message

EXCEPTION: Cannot resolve all parameters for ‘LoginPage’(?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that ‘LoginPage’ is decorated with Injectable.

I have add the http.dev.js and Rx.js in the index.html, but it seems not helping

This is my ionic info:

Cordova CLI: 6.1.1
Ionic Framework Version: 2.0.0-beta.3
Ionic CLI Version: 2.0.0-beta.24
Ionic App Lib Version: 2.0.0-beta.14
ios-deploy version: 1.8.5
ios-sim version: 5.0.8
OS: Mac OS X El Capitan
Node Version: v4.4.1
Xcode version: Xcode 7.3 Build version 7D175

I have no idea what is the problem, below is the source code

import {Page, NavController, NavParams} from ‘ionic-angular’;
import {Http} from ‘angular2/http’;
import {Injectable, Inject} from ‘angular2/core’;
import {HomePage} from ‘…/home/home’;

@Page({
templateUrl: ‘build/pages/login/login.html’
})

@Injectable()
export class LoginPage {

constructor(@Inject(Http) http: Http) {
	this.http=http;
}

}


#2

You can switch to TypeScript and not worry about this any more, or you’ll have to add a desugaring method to LoginPage that looks something like:

static get parameters() {
    return [[Http]];
}

#3

Hi thanks you reply.

I have remove the inject annotation and use the solution you provided, however I get the following message

browser_adapter.ts:73 SyntaxError: Unexpected token C

This is my source code

import {Page, NavController, NavParams} from ‘ionic-angular’;
import {Http} from ‘angular2/http’;
import {HomePage} from ‘…/home/home’;

@Page({
templateUrl: ‘build/pages/login/login.html’
})

export class LoginPage {

constructor(http) {
	this.http=http;
}

static get parameters() {
	return [[Http]];
}

}


#4

I sorry this is my problem, I already fix the issue.

Thank you for your help.

I wanted why need to use this static method to call the http request in js file?