Jump to content

How do I include AngularJS in JS file?


smus

Recommended Posts

How can I include AngularJS in JS file? Not in HTML, but in JS file. I read that it is possible to use "require" NodeJS command, to call Angular lib functions. This code generates an error ('window is not defined'):
  1. const ang = require('../lib/angular');
  2. let myApp = ang.module("myApp", []);
  3. console.log(myApp);
  4.  

Is there a way to fully include it in a js file?

Link to comment
Share on other sites

AngularJS is designed to be used in a browser. It relies on the existence of a window object, but server-side Javascript does not have a window.

Link to comment
Share on other sites

Thanks, Ingolme. Let me extend my question then: is it possible to include one .js file in another one? Hypothetically. For example, because of the fact I have too much code in one file.

Link to comment
Share on other sites

If you're working in a browser, the best approach is to add another <script> tag to your HTML document, everything declared globally in one Javascript file is accessible in all the other files that follow it.

You seem to be working in Node.js. My experience with server-side Javascript is limited but there's a discussion about it here: https://stackoverflow.com/questions/4481058/load-and-execute-external-js-file-in-node-js-with-access-to-local-variables

  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...