bourax bourax - 1 year ago 40
Javascript Question

compare PHP and AngularJS values

I use jQuery-upload script to manage some users photos, I have a simple html script where I use some AngularJS data:

<input type="radio" name='profile_pic' value="{{}}">

I want to check if the
{{}} == $userProfile['profile_pic']
the direct comparison doesn't work, how can I use
to add "checked" to the radio option when the value of the radio is the same as $userProfile['profile_pic'] ?
I tried this but it doesn't work, I know PHP reads {{}} as a string itself then AngularJS replaces with its value:

$checked = '';
if ('{{}}'== $userProfile['profile_pic']){
$checked ='checked'}
<input type="radio" name='profile_pic' value="{{}}" <?= $checked ?>>

Jai Jai
Answer Source

It's not the way to compare two different values. PHP runs at server while angular runs in browser way later.
So simply you can't compare these two different scoped values like this. But there you have $http service to send a request to server, compare it there and send a response at the client.

What can be done:

  1. Create a service/factory which sends a request to the server with the data you want to send.
  2. Do compare at the server and create a response for the client.
  3. In the success handler you can update the model for any change reflection.