smus Posted May 5, 2018 Share Posted May 5, 2018 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'): const ang = require('../lib/angular'); let myApp = ang.module("myApp", []); console.log(myApp); Is there a way to fully include it in a js file? Link to comment Share on other sites More sharing options...
Ingolme Posted May 6, 2018 Share Posted May 6, 2018 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 More sharing options...
smus Posted May 12, 2018 Author Share Posted May 12, 2018 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 More sharing options...
Ingolme Posted May 12, 2018 Share Posted May 12, 2018 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 1 Link to comment Share on other sites More sharing options...
smus Posted May 13, 2018 Author Share Posted May 13, 2018 Exactly, I've just found it easier to check the scripts using command prompt, than a browser console. Thank you Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now