Search code examples
javaangularjsangular-ngmodel

Binding ngmodel to a value that is received from the java controller


How do i bind a value that is received in the .jsp from a java class(using model map add attribute method) to ng-model in angular js? I have tried the below options but the value is not being fetched into the model.

  1) <input ng-show=true name="emailId" id="check" type="text"
                ng-model= "user.name" ng-init="user.name=${UserName}">
  2)<input ng-show=true name="emailId" id="check" type="text"
                ng-model= "user.name" ng-init="user.name={{UserName}}">

Solution

  • I don't see value attribute there at your input element.

    <input ng-show=true name="emailId" id="check" type="text" value = ${UserName}
                    ng-model= "user.name" ng-init="user.name=${UserName}">
    

    As said in comments either map your value to user.name or ${UserName}. Since in your ng-init you are mapping user.name modlel to your jQuery ${UserName}.