Forum Discussion
Mike Jansen
Jun 20, 2017Iron Contributor
SharePoint framework > refer to custom .js file and call function
I started this one before: https://techcommunity.microsoft.com/t5/SharePoint-Developer/Sharepoint-framework-gt-reference-to-custom-javascript/m-p/77073#M2638 Sorry to start a new conversation again ...
- Jun 23, 2017
Took some time but I figured it out. This is what I did:
1. No reference in the "Config.json"
2 Changed my custom script:
var CustomScript = function testFunction() { alert("test"); }; module.exports = { CustomScript: CustomScript };3. in my .ts file did in the render method
const MyCustomScript: any = require('./myscript'); MyCustomScript.CustomScript()Now my "alert" shows up.
Mike Jansen
Jun 23, 2017Iron Contributor
Took some time but I figured it out. This is what I did:
1. No reference in the "Config.json"
2 Changed my custom script:
var CustomScript = function testFunction() {
alert("test");
};
module.exports = {
CustomScript: CustomScript
};3. in my .ts file did in the render method
const MyCustomScript: any = require('./myscript');
MyCustomScript.CustomScript()Now my "alert" shows up.
- Mike JansenJun 23, 2017Iron Contributor
I do have an additional question.
What if I want to refer to another .js file from "myscript.js" ?
Just like:
<script src="blablabla"></script>
- Mike JansenJun 27, 2017Iron ContributorManaged to get is working by using:
"const myCustom = require('./myscript');"