Skip to main content
1-Visitor
June 21, 2018
Solved

Including js file from resources

  • June 21, 2018
  • 2 replies
  • 6656 views

Hi,

 

I have a *.js file with functions that I will call from home.js. I uploaded the js file into the resources. How can I include this js file, so that I can call the functions?

Best answer by ClayHelberg

There's a function for this:

 

$scope.app.fn.loadResourceScript("Uploaded/adapter-latest.js");

 

Just replace "adapter-latest.js" with your JS file name, and Bob's your uncle.

 

--Clay

2 replies

1-Visitor
June 21, 2018

So i have not had time to try this yet but had the same question and someone suggested this code might work.

 

document.write('<script type="text/javascript">
console.log("In Prod Mode: Trying to load Pre-cache")
</script>');
document.write('<script src="script2.js"></script>'); //might need to make a better path to the js file like app/components/myJS.js
18-Opal
June 21, 2018

There's a function for this:

 

$scope.app.fn.loadResourceScript("Uploaded/adapter-latest.js");

 

Just replace "adapter-latest.js" with your JS file name, and Bob's your uncle.

 

--Clay

drichter1-VisitorAuthor
1-Visitor
June 22, 2018

Thx this works 🙂

 

Is there any way to include css files? loadResourceStyle will not work.^^

 

PS: I can not find a api, have someone a link to an api?

drichter1-VisitorAuthor
1-Visitor
June 22, 2018

Ok I found a solution for this. Add this

 

@import url(#{$resources}/Uploaded/test.css);

in Application Styles