Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I am making some Qlik Sense extension, and I would like to use external .js files.
I was looking to a Qlik Sense documentation page and tutorial, and I don't know what I am doing wrong.
main.js
define( [
'jquery',
'qlik',
'./scripts/test',
'text!./css/myStyle.css'
],
function ( $, qlik, test, cssContent ) {
'use strict';
....
paint: function ( $element, layout ) {
test.hello();
}
});
test.js
function hello() {
console.log(' api test: my');
}
What I get in console is:
TypeError: Cannot read property 'hello' of undefined
My next question is if/when will my external .js file contain some external library (npm install packages), is it enough to just npm install all necessary packages, or do I need to do something else?
Hi,
Your test.js file should define a module that returns an object with a hello method. The define .... return { } is necessary.
Erik Wetterberg
Hi,
Your test.js file should define a module that returns an object with a hello method. The define .... return { } is necessary.
Erik Wetterberg
Yes this do the trick.
I then found this link that could help others who stumbleupon same problem.
What about my second question? Do you know about npm modules?
Also, if I add another method, the error come back. Should be there only one function? This seems like bad design.
How do I make more than one method inside?
define([
"jquery"
],
function (jq)
{
return {
log: function (error, response, body) {
console.log('test1');
}
hello: function () {
console.log('test2');
}
}
});
Hi,
You need to separate the functions with comma:
},
hello: function(){
What you return is just a javascript object, so you need to follow javascript object syntax. Alternatively you could do like this:
var module = {};
module.log = function() {...};
module.hello = function(){...};
return module;
Erik Wetterberg
Please mark as helpful if you find this useful.
Thank you for that, I miss this
But I still have second problem.
If I do:
const request = require('request');
I get error....
Do you know how to bring modul to this (separate, with only functions) js file?
Marko