2

I am not able to set default value of textbox using php while using angularjs

<input type="text" ng-model="formToken" value="<?php echo $token; ?>">

In this the output is not showing token value in textbox, but when I remove ng-model="formToken" then token value showing in value attribute, otherwise its showing blank. I want to pass $token to textbox value attribute, how can I fix this?

1
  • Sounds like something in Angular $scope must be overriding this. Commented Aug 26, 2014 at 12:43

1 Answer 1

3

That's because you're binding the value of the input to formToken, which is likely not set. Setting value will not set the value on the scope (because of how angular parses the DOM).

To set the value through PHP, you could use the ng-init attribute:

<input type="text" 
       ng-model="formToken" 
       ng-init="formtoken = '<?php echo $token; ?>'"> 

Alternatively, you could set the value in your controller using

scope.formToken = whateverYouLike;
Sign up to request clarification or add additional context in comments.

Comments

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.