admin管理员组

文章数量:1332345

i wants to access session value from angular js.or set it in a text field.But its not working.

<input type="text" id="uname" value="<%=session.getAttribute("username")%>" ng-model="username" readonly="readonly">

when i set the value of normal text field its working, like

<input type="text" id="uname" value="<%=session.getAttribute("username")%>"  readonly="readonly">

but after adding ng-model its not working. How i will do this?Please anybody help me.

i wants to access session value from angular js.or set it in a text field.But its not working.

<input type="text" id="uname" value="<%=session.getAttribute("username")%>" ng-model="username" readonly="readonly">

when i set the value of normal text field its working, like

<input type="text" id="uname" value="<%=session.getAttribute("username")%>"  readonly="readonly">

but after adding ng-model its not working. How i will do this?Please anybody help me.

Share Improve this question edited Mar 29, 2017 at 11:46 parvezalam khan 4902 silver badges11 bronze badges asked Mar 29, 2017 at 10:57 S dgS dg 211 gold badge1 silver badge7 bronze badges 3
  • It will be good if you move the session.getAttribute("username") to controlelr – Sravan Commented Mar 29, 2017 at 11:08
  • How will do this?@Sravan – S dg Commented Mar 29, 2017 at 11:13
  • Use JSP on JavaScript files is clearly a bad solution. And controller is placed in JS. So if you want to use this approach, you need e client-server munication get session values from server. – Anton Stepanenkov Commented Mar 29, 2017 at 11:23
Add a ment  | 

1 Answer 1

Reset to default 5

It's angular's normal behavior. Try to use
ng-value="'<%=session.getAttribute("username")%>'" which is better
or
ng-init="username = '<%=session.getAttribute("username")%>'"

本文标签: javascriptHow to access Session value from AngularjsStack Overflow