How to import Javascript in angular?

Asked

Viewed 1,705 times

1

Greeting to all,

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

Archives 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 difficulty now is importing Javascript files, I don’t know how to do it! , I tried to put the Javascript path in this same line of code above and it didn’t work, and then analyze this file better angular-cli.json found this code snippet

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

This file is at the root of the project, it is found 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 don’t know if you understand my question, but briefly I need to connect a Javascript file to create javascript implementations in the angular project, that’s it!

For those who want to take a look at my project is here:

1 answer

1


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

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

Then add in typings.d.ts

declare var nomeVariavel:any;

In your file, import as follows:

import * as variable from 'nomeVariavel';

Interesting to restart ng server after this, in case it is already running.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.