0

=== Lets just say i already have setup my App and Controller ====

test.phtml

 $var = "Welcome";

myangular.js

$scope.var = "<?php $var; ?>" //not sure about this part

console.log(var)

MY PROBLEM is that, i cant display the console.log(var) it says "undefined?"

Is it possible? i want to pass the PHP VARIABLE to ANGULAR onload, right when page is loaded..

BTW im using phalcon framework

2 Answers 2

2

you need to echo the variable:

$scope.var = "<? echo $var; ?>"

or in a shorter way:

$scope.var = "<?=$var; ?>"

technicly both are the same.

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

1 Comment

Although this is a simple and effective way, most of the time your js will be written inside independent js files. In those cases you'll need to assign to a global javascript variable (to your index.html) rather than to the script directly.
1

I would suggest exposing a public API from your PHP application and then calling it using the $http service in angular-js.

$http.get('APIURL', {cache: true})
     .success(function(data){...})
     .error(function(data){});

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.