2

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.

3
  • It will be good if you move the session.getAttribute("username") to controlelr Commented Mar 29, 2017 at 11:08
  • How will do this?@Sravan 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 come client-server communication get session values from server. Commented Mar 29, 2017 at 11:23

1 Answer 1

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")%>'"

Sign up to request clarification or add additional context in comments.

3 Comments

<input type="text" id="username" ng-init="username = <%=session.getAttribute("username")%>" readonly="readonly"> But when i call it $scope.username, it return undifined @Anton Stepanenkov
@Sdg Sorry, forgot to add quotation around '<%=session.getAttribute("username")%>'. I've edited the answer
What would be the syntax for setAttribute when wanting to set an angular variable to the session parameter?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.