I'm trying to write some logic in JavaScript file in my custom component but the use function is not firing the console.log. Does anyone know why it won't work. I even tried using window.alert but that won't work either. but I can create a var and assign a string value and display that value through expression in HTL.
Here is the the JS code.
use(function () {
var props = {
test: "test",
test2: "test2"
};
console.log("----------------Test_---------")
return {
// anything exposed here can be used inside your template
props: props,
};
});
Solved! Go to Solution.
Views
Replies
Total Likes
As you are using Use API, which is actually converted into JAVA instead of loading as a JS in a browser, you have to use JAVA object to log the information. Below code is working fine on my local.
log.info("Using USE API");
Also this log will be generated in server log files instead of browser console, so you have to create a log file of the component you are using for example if your component is /apps/we-retail/components/sample then you have to create a log file of : apps.weretail.components.sample from http://localhost:4502/system/console/slinglog.
Please update if you need sample working code.
Hi @snowwhite92
Go to developer tools - > Source Tab -> Find your JS code and place a debug breakpoint on your code. See if the debugger stops at your breakpoints. See if the code is actually executed.
Thanks
This is server side javascript. window.alert() is for client side js.
Try to Add a new logger in AEM and print the statements with log.debug statements
please check this https://jimfrenette.com/aem/javascript-use-api/ for help.
As you are using Use API, which is actually converted into JAVA instead of loading as a JS in a browser, you have to use JAVA object to log the information. Below code is working fine on my local.
log.info("Using USE API");
Also this log will be generated in server log files instead of browser console, so you have to create a log file of the component you are using for example if your component is /apps/we-retail/components/sample then you have to create a log file of : apps.weretail.components.sample from http://localhost:4502/system/console/slinglog.
Please update if you need sample working code.
Views
Likes
Replies