Reputation: 5618
I am migrating my Ionic1
project to Ionic2
these days. Fun!
One hurdle right now is to migrate a long list of tool functions written in JS such as CmToFeet
/ InchesToCM
/ FarenheitToCelsius
to the Ionic2 project.
I do not know how to properly include these files in the project and make sure they will be considered for the build process. Can I just include them in the index.html
and they automatically will be available? Do I need to do more?
Any tips?
Upvotes: 2
Views: 57
Reputation: 44669
One of the easiest ways to do that would be to treat it just as another asset. To do so, you can create a folder in src/assets/scripts
, put those js files there and then add the script tag in your index.html
file like this:
<script src="assets/scripts/jsFileName.js"></script>
If you used to call those functions by doing something like CmToFeet.methodName()
, now you will need to declare CmToFeet
variable to prevent typescript errors
import {... } from '...';
declare var CmToFeet: any; // <- Like this
@Component({
selector:'my-page',
templateUrl: 'my-page.html',
})
export class MyPage {
// ...
}
Please notice that by doing things like this, the autocomplete features won't work since it's declared as of type any
.
Upvotes: 1