Home » Javascript » How to create and import a js file module into Angular 5 App component?

How to create and import a js file module into Angular 5 App component?

Posted by: admin October 29, 2018 Leave a comment

Questions:

I’ve created and testing a simple Angular 5 web-app. I want to add my own js logic to some app components, but none of the options I’ve tried does not work. The attempts were using:

import * as ExampleModule from ‘./exmodule.js’; in TS

and:

define([“require”, “exports”], function(require, exports){
exports.value = 123;
});
in JS

…aslo tried this example:

Object.defineProperty(exports, "__esModule", { value: true });
exports.values = [{name: 'Example1', type: 'One'},
 {name: 'Example2', type: 'Two'}];

…in JS

I’m actually new to this. Could somebody tell, how to properly create js files, import them to ts components and use? Thanks in advance!

Answers: