0

I have to send "id" of flight on which manager clicks approved so do to that i want php var to go in angular var somehow. I did this where the error mentioned in title occurs.

<input type="hidden" ng-init="id[index++]='<?php echo $flight['id']; ?>'">

Any idea about which '[' is angular compiler talking about and how to write correct expression like this? Much thanks. In angular :-

$scope.id=[];
$scope.index=0;

Okay i got a great answer which says to escape quote you can use '\' and now I am trying :-

<input type="hidden" ng-init="id[index++]='<?php echo $flight'\['id']'; ?>'">

But it still isn't working and is giving this error "unexpected "[" at line: blah". Can anyone add "\" in my above mentioned line and plis make me get rid of this headache?

Asim
  • 1,208
  • 1
  • 13
  • 26
  • I'm assuming it's the `]` after `id` seeing the `'` left of `id` is closing the string. `' – Nope Sep 04 '17 at 13:26
  • I suspect so, but how to tackle this? – Asim Sep 04 '17 at 13:28
  • @Escape the quote. What ever the syntax is in PhP – Nope Sep 04 '17 at 13:28
  • Can you please write full syntax? – Asim Sep 04 '17 at 13:29
  • 1
    @Fran That wont work because the compiler is from angular not from PHP as the description says. Is there any way you can assign that into a variable? – Agustin Sep 04 '17 at 13:31
  • Searching SO for `escape single quote in php` ► https://stackoverflow.com/questions/38646653/escape-single-quotes-in-string-containing-single-and-double-quotes – Nope Sep 04 '17 at 13:31
  • i read that answer but can you add "\" in my line and answer so that it can help me and others. I can't understand where to add '\" :/ – Asim Sep 04 '17 at 13:34
  • @AsimRaja The other answer already helps others, assuming it's the fix, if it is then your question would be a possible duplicate to that question instead. Unless off course your issue is totally different. Hence, apply the changes, test it and if it fixes it, it's a possible duplicate, if not you can update your question with the code you tried that still isn't working. – Nope Sep 04 '17 at 13:40

1 Answers1

1

You're closing your string in ng-init before it is finished. Try this:

<input type="hidden" ng-init="id[index++]='<?php echo $flight[`id`]; ?>'">
mikaelrs
  • 325
  • 1
  • 10