Sandeep Singh Sandeep Singh - 1 month ago 13
AngularJS Question

How to access JSP variables inside the angular js constants

i have a module with the constants

angular,module('myconstants',[]).constant('url','<%=MyBean.getUrl("uri-prefix")');


When i'm using this url constant, it is showing as a string('
<%=MyBean.getUrl("uri-prefix")');
), but actually it should call the MyBean.getUrl method.

any suggestions?

Answer

If you access variables in JSP file, you can modify like code below

angular,module('myconstants',[]).constant('url','<%=MyBean.getUrl("uri-prefix")');

angular,module('myconstants',[]).constant('url','<%=MyBean.getUrl("uri-prefix")%>');

But If code is placed outside JSP file, you can use global variable to access variables.

you can type code below (in a JSP file)

<script>
url = '<%=MyBean.getUrl("uri-prefix")%>'
</script>

then you can access (in other javascript files)

angular.module('myconstants',[]).constant('url',url);
Comments