Hi im using Angular 7 and Spring framework, and i need to run a external JS function in TS file.
I tested on a single Angular application and it works well, when i compile the Angular code and put the result on spring resources and generate war file the script is not recognized, the console in browser shows "function undefined".
I modified Angular.json file setting the path of the script in "scripts" section, even if i set in index.html < script src="path/to/script2run.js"> it doesn´t works.
How can i load in spring application my JS file?
Can you help me please?
Regards
Where do you keep your JS file?
If it's working when you run with ng serve it should work when it's compiled as well.
So I think issue in the path. Try to see if this file is coming together with your intex.html.
You can do in Chrome browser:
right click -> inspect -> Network and refresh the page and you will see all files coming from server side to browser. If your JS file is not there than it's path issue make sure your js file is exist from where you are trying to get it.
Related
New coder here. As the title suggests, I spent the past two hours trying to run a simple Javascript on VSC with no avail. Could someone help me set my sandbox up? Here is a screenshot.
Much appreciated!
kt
Downloaded VSC
Downloaded nodejs
Entered "node scriptname.js" in terminal
Error message above
Your specific error is caused by you running node from the console and providing the wrong path to test.js.
You are in the Desktop directory and just specifying a file name, so Node is looking for test.js in the Desktop directory.
You have saved test.js in a directory called Coding Practice.
You need to either:
cd to the correct directory or
Provide the path to the directory as part of the second argument
Typically, when using VS Code, you would pick the Open Folder option from the File menu to work within your project's root directory (i.e. Coding Practice) which will provide you with a file list and do things like open the terminal in that directory by default.
Once you solve that problem you will run into your second problem.
The contents of test.js isn't JavaScript!
It's an HTML document with JavaScript embedded in it.
You need to:
Give it a .html file extension and
Open it using a web browser and not with Node.js (the traditional way to do that from within VS Code is with the live server extension but you'll really want to have VS code open in the right directory (as above) for that.)
You can't even remove the HTML from the file and run it with Node.js because alert (the function you call) is a Web API and not core JavaScript nor a Node.js API.
so I am making an application that requires a backend API, and it uses certain node_modules which don't work when compiling with Electron. To fix this, I put the API code into a separate JavaScript file, which I am attempting to fork using child_process.
I have gotten this to work when compiling, but it immediately stops working after I move the "win-unpacked" folder or try to install the app using the compiled installer.
I have checked, and it is not the path that is wrong, it is correctly pointing to the file. From testing, it appears that the file actually does get forked, but immediately exits with the status code 1.
I can't use require(./filepath.js) because that will just include the code in the compiler, which doesn't work with the modules I am using.
I am hoping someone knows what is wrong and what I should do to fix it, or have any ideas for other ways to run the server code without including it in the compiler.
I am using Vue.js 3 and vue-cli-electron-builder version 2.1.1
The server I am attempting to run is a express server.
In my MVC5 web application I use two bundles for a page, one contains the common JavaScript files for all the pages and the other bundle is specific for the page. This works fine in development environment but the page specific bundle does not load in the staging. The Rendered script tags are as below.
<script src="/bundles/jsAll?v=72eJMPeVrT1mvbZw1VAU7y6r7vodOImt5NOMq4Gcp581"></script>
<script src="/bundles/my-page?v="></script>
Could not figure out why this happens...
The problem was locally this works because all the files are available, but did not work after deployment because the script file was not included to the project, hence the file does not get deployed to the destination. Since the file is missing the bundle has nothing to serve, so there won't be a version nor content.
I have a project with Java REST backend and HTML + JavaScript frontend, and I'm trying to debug the JavaScript part.
My project is build with maven and deployed as an exploded war. The debugging works fine only if I put the breakpoints in javascript files residing in "target" folder, e.g the folder that the project compile output goes to.
How can I configure the Javascript debugger with where my scripts are?
I am going to be working on an angular project without internet access, so my links to the cdn will not function. I would like to save the angularjs library to a folder inside of my project. Here is what I have tried:
I went to the cdn link, copied all of the text, pasted it into a file, and saved that file as angular.min.js . I then commented out the script tag for the cdn in my index.html file, and put in a new script tag specifying the path to the new saved file. When I open my project, I get the error "Uncaught ReferenceError: angular is not defined."
Here are the relevant pieces of my project's file/folder structure:
project
|_core
| |_public
| |_app
| |_index.html
|_libraries
|_angular.min.js
And here is my script tag:
<script src="./../../../libraries/angular.min.js"></script>
And here is the link to the cdn from which I copied the text:
https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js
Are you using a local webserver of any kind? Angular and many scripts need to be loaded from http and not file://. For this, you could use python's SimpleHTTPServer: python -m SimpleHTTPServer 8080 -- will open an http server on http://localhost:8080, open the url in your browser and you should be good to go. Also note that the order in which you load the scripts in your HTML is important, and Angular needs to be loaded before all modules of code that use it.
<script src="../../../libraries/angular.min.js"></script>
How about this ?
Have you just tried this?
<script src="/libraries/angular.min.js"></script>
Maybe your server start website (localhost:80) from the root of your project
You can use Grunt task to minify and concatenate all files. You can read the docs of GruntJS. Very useful.
http://gruntjs.com/sample-gruntfile
see the concatenate section.
if you do that manually you have check the sequence of lib files. Angularjs lib need to be on top.
There are chances of errors.
yes just to include a file you don't need Grunt
check in chrome inspect developer tool in network tab if your file angular.min.js loaded properly. If not you can change the path and try but if it is loading and still you are getting same error so please create jsfiddle or plunker of your file so that we can look it in detail.