Is tutorial wrong on Ionic site?

According to this tutorial , my code is showing errors in Visual Studio Code. It showing errors for

`import {Page, NavController} from ‘ionic/ionic’;

@Page({
templateUrl: ‘app/hello-ionic/hello-ionic.html’
})
export class HelloIonicPage {
constructor(nav: NavController) {
this.nav = nav;
}
}`

However, if I change import to ‘ionic-framework/ionic’ and put private in front of nav variable name in constructor it seems to work. Is this correct?

`import {Page, NavController} from ‘ionic-framework/ionic’;

@Page({
templateUrl: ‘app/hello-ionic/hello-ionic.html’
})
export class HelloIonicPage {
constructor(private nav: NavController) {
this.nav = nav;
}
}`

reference:

The import is in fact wrong and should be ‘ionic-framework/ionic’ as you discovered.

As far as the nav parameter, you have a couple options. Either give it an access modifier (private, public, etc.) OR you have to explicitly declare the variable before your constructor. The reason you can do either is that TypeScript will compile the access modifier option to the latter as a way to save typing.

Please note that ionic-framework/ionic import is like this in the typescript versions of the starters, in the JS ES6 versions ionic/ionic works due to webpack.config.js alias.

1 Like