2

I have an field where the id is set via php:

<input name="user_id" type="text" value="<?php echo $this->r->user_id; ?>"  ng-model="entry.user_id" >

But the value does not appear in the field.

How can I set it from php to angular js?

3 Answers 3

2

Set the initial value of the ng-model using ng-init instead:

<input name="user_id" type="text" ng-model="entry.user_id" ng-init="entry.user_id = <?php echo $this->r->user_id; ?>" >

I'm not sure about the php syntax, but this will set value for you as long as the controller has an entry object available.

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

Comments

2
<input type="text" ng-model="enquiry.companyName" ng-init="enquiry.companyName='<?php echo $_SESSION['COMPANYNAME'] ?>'"  name="companyName">

Sigle quote around php block is important.

Comments

0

You might want to try ng-value as well. Might fit your situation better. I didn't come across it until today:

<input name="user_id" type="text" ng-value="<?php echo $this->r->user_id; ?>"  ng-model="entry.user_id" >

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.