I am new to OOP and typescript. I am working on Ionic2 project.
I have a page list
list
- list.html
- list.ts
- list.scss
I have create a new class/.ts file in same folder
export class TestClass{
constructor(){
console.log("I am test class");
}
}
then In list.ts I use
import { Component,ViewChild,ElementRef,Renderer2 } from '@angular/core';
import { NavController, NavParams,Platform,Content } from 'ionic-angular';
import {TestClass} from 'test.ts';
declare var Phaser:any;
@Component({
selector: 'page-list',
templateUrl: 'list.html'
})
export class ListPage {
testClass:any = new TestClass();
constructor(public navCtrl: NavController, public navParams: NavParams, private _platform:Platform) {
};
};//end class
this give me error Cannot find module "test.ts"
How can i import my custom class in Ionic2 page?
Please help.
testClass: any = new TestClass();is insane.testClass: any = new TestClass();. WritetestClass = new TestClass();instead, otherwise you might as well not use TypeScript../if they are in the same folder of the file you are including them from. Not using./means to ask to node.js to resolve the module innode_modules, which is the folder where node modules are actually stored. This rule applies to every single javascript project really, but in your case (and in Ionic2) it's pretty important.