Tried creating Services and use it on component , but ionic 2 seems not understanding the Type while declaring any variable and giving error "Unexpected Token on line *" For ex :
export class Login {
id:number;
username:string;
password:string;
}
Declaring this class like this and use it any component it says Unexpected Token on Line 2 , 3 ,4 and if you remove all Type of the variable it gives error “Missing class properties transform. while parsing file”
Same Applies while initiating services in the constructor of a Component class For Ex :
constructor(private _router : Router,private _loginservice: LoginService){} >> Its gaves the same Unexpected token error
As per Angular 2 this is the correct Syntax which I am using and worked properly if I use only Angular 2 but not on Ionic 2
I guess that you’re trying to use types in a JavaScript project. Types and class properties are valid only in TypeScript projects. For more details check out the following post:
Ionic supports both TypeScript and JavaScript projects. When you’re creating a new project you can choose if it should be in TypeScript or JavaScript. Currently JavaScript is the default (however this is going to change) so if you haven’t specified explicitly that you want a TypeScript project then your project is in JavaScript.
To start a new TypeScript project type (note the --ts - it indicates that you want TypeScript):