javascript - How to pass a PHP variable to an AngularJS config -


let's have html file has angularjs loaded in 'ngroute'.

then i'm initialize app making index.php file (i'm not displaying basic html tags + angular js includes here):

<?php $path = 'www.test.com' ?>  <div ng-app="testapp" ng-init="path='<?php echo $path ?>">    <div ng-view></div>     </div> 

i'm trying pass php variable angularjs app config, this:

// module var test = angular.module('testapp', ['ngroute']);  // routes test.config(function($routeprovider) {     $routeprovider     .when('/', {         templateurl: $rootscope.path + '/pages/display.htm',         controller:  'testcontroller'     })  });   // controllers test.controller('testcontroller', ['$scope', function($scope) {  }]); 

this not work though because $rootscope not definied. can tell me missing here?

based on comments wanting keep php , scripts separate add script tag variable can access anywhere in angular

<script>      var mypathvar = '<?= $somevar; ?>'; </script> 

then can want inside angular such add constant , pass $rootscope in config or whatever


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -