[英]Accessing OSGi config data in app.config in AngularJS
I have a jsp file which is getting data from OSGi configuration in AEM, like below 我有一个jsp文件,它从AEM中的OSGi配置获取数据,如下所示
<c:set var="myParam" value="${myConfig.myParam}" scope="request"/>
Now in my JS file, I am initalising my angular app like below: 现在在我的JS文件中,如下所示启动我的角度应用程序:
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? 如何从我的JSP文件中检索此
myCustomDataFromJSP
? 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; })());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.