-1

I'm new in angularjs and after looking in every site and forum without answer, somebody can help me to selve this?

i have this html with php code, and i want to pass php var into angularjs event.

 <a ng-init="changeCat=<?php echo $id_cat, $category; ?>" id="cat_<?php echo $id_cat; ?>" class="cat-list" href="#"><?php echo $category->name; ?></a>

thanks in advance!

1
  • And, what does the resulting html look like after you php is executed? You're using php to write an angular template, so you should test that it writes the template correctly first, before trying to use the template. Commented Feb 11, 2015 at 15:32

1 Answer 1

1

assuming you have a method changeCat() you can pass it php variables using something like ng-init="changeCat(<?php echo $id_cat; ?>)". I am assuming you want ng-int at this point but it should give you enough to get going with.

also try searching 'pass php to ng' or 'pass php variable to angular controller'... results should be similar.

EDIT:

As @Kevin B said you may want to change the way you are doing things but that said.

If you are to use more that one variabel then have a look at this: Laravel/Angular: passing data within php page to angularjs

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

3 Comments

tks!!! MrPickles for your help, is very hard to find documentation related with angularja and php, i'll try your solution and i'll comment!
@user3585926 that's because generally you don't use php to build angular templates, instead you build php webservices that return json to angular, then angular controllers/views/services take that data and build the page.
it works! but when i try to pass more than one var it shows me an error, this is the code with the second var, <?php echo $id_cat;.$category->name; ?>

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.