I have a jsp file which is getting data from OSGi configuration in AEM, like below
<c:set var="myParam" value="${myConfig.myParam}" scope="request"/>
Now in my JS file, I am initalising my angular app like below:
var app = angular.module('myapp', []);
app.provider("$provider1", [function () {
// Default configuration
var config = {
key1: 'value'
};
return {
configure: function (params) {
angular.extend(config, params);
},
$get: ['$rootScope', function ($rootScope) {
return {
config: config
};
}]
};
}]);
app.config(['$authProvider', function($authProvider) {
$authProvider.configure({
key1: 'myCustomDataFromJSP'
})
}]);
How can I retrieve this myCustomDataFromJSP
from my JSP file? In config phase we can't access scope.
Thanks
I would do it in next way:
<div id="config" data-jspvar="${myParam}"> </div>
Like this:
app.constant('myCustomDataFromJSP', (function() {
// Define your variable
var myCustomDataFromJSP = ...; //you can use smth like this
//window.document.getElementById('config').dataset.jspvar
return myCustomDataFromJSP;
})());
上面的答案是一个很好的答案,但是在DOM中有一个隐藏的输入而不是一个div很好。
<input type='hidden' id="config" data-jspvar="${myParam}"> </input >
app.constant('myCustomDataFromJSP', (function() { var myCustomDataFromJSP = //get the value here return myCustomDataFromJSP; })());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.