Reputation: 153
I don't know what I did wrong, but it says Syntax error with codes copy pasted from official ionic2 docs.
SyntaxError: D:/Manson/Arts/Ionic/IonicTodo2/app/pages/list/list.js
: Unexpected token (14:23) while parsing file: D:\Manson\Arts\Ionic\IonicTodo2\app\pages\list\list.js
For the full code click here.
constructor(nav: NavController) {
Upvotes: 1
Views: 230
Reputation: 5357
It looks like you're using types from Typescript, while your code is in a plain Javascript file (.js). nav: NavController
declares that nav
is of type NavController
.
When you run ionic serve
, Ionic runs webpack
to compile and package your code. Since this is not a valid JS syntax, it fails.
Ionic 2 is based on Angular 2, which was written in Typescript
. While Angular 2 can be used with plain Javascript, it is mostly undocumented, and they basically recommend using Typescript when developing Angular 2 applications.
When you create a new Ionic 2 project, you should use the --ts
flag if you want your project to be in Typescript. The command should be:
ionic start MyIonic2Project --v2 --ts
After that, copy-pasting the Ionic 2 tutorials should work for you.
Upvotes: 1