How to import non-angular Javascript?

1

Greeting for all,

I know how to import css files into a project made with the new version of Angular as you can see below:

Files angular-cli.json

 "styles": [
        "../node_modules/bootstrap/dist/css/bootstrap.css",
        "../node_modules/ng2-toasty/style-bootstrap.css",
        "../node_modules/font-awesome/css/font-awesome.min.css",
        "../node_modules/primeng/resources/primeng.min.css",
        "../node_modules/primeng/resources/themes/omega/theme.css",
        "styles.css"
      ],

But my problem now is to import JavaScript files, I do not know how to do it !, I tried to put the JavaScript path in the same line of code above and it did not work, and then I'd better analyze this angular-cli.json I found this code snippet

"e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },

This file is at the root of the project, it looks like this:

// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts

const { SpecReporter } = require('jasmine-spec-reporter');

exports.config = {
  allScriptsTimeout: 11000,
  specs: [
    './e2e/**/*.e2e-spec.ts'
  ],
  capabilities: {
    'browserName': 'chrome'
  },
  directConnect: true,
  baseUrl: 'http://localhost:4200/',
  framework: 'jasmine',
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
    print: function() {}
  },
  onPrepare() {
    require('ts-node').register({
      project: 'e2e/tsconfig.e2e.json'
    });
    jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
  }
};

I do not know if they understood my question, but briefly I need to connect a JavaScript file so I can create javascript implementations in angular design, that's it!

For anyone who wants to have a look at my project you are here:

    
asked by anonymous 28.12.2017 / 09:15

1 answer

1

Declare the scripts within the angular-cli.json file.

"scripts": [
    "../path" 
 ];

Then add to typings.d.ts

declare var nomeVariavel:any;

In your file, import as follows:

import * as variable from 'nomeVariavel';

Interesting to restart the ng server after doing so, if it is already running.

    
28.12.2017 / 12:30