javascript - getting undefined php value in angular js file -
i have php session variable set in index.php file. using ng-init assigning session value variable can use in angularjs controller file. index.php file
<body ng-app="myapp">     <div ng-controller="restaurantcontroller" ng-init="total=0;something='<?php echo $_session['rname'] ?>'" class="container">         <div class="col l4 s4 container">         <label>search</label>    <input type="text" ng-model="search.name">     </div>         <div ng-repeat="item in items | filter:search" class="container">             <h3>{{item.name}}</h3>             <p>category:{{item.category}}</p>             <p>price:inr {{item.price}} /-</p>             <br/>             <button ng-hide="item.added"  ng-click="process(item)">add</button>             <button ng-show="item.added" class="ng-cloak">remove</button>         </div>         <h1>total:<span ng-model="total">{{total}}</span></h1>     </div>     <script src="../angular/app.js"></script>     <script src="../angular/restaurantcontroller.js"></script>     <script src="../materialize/js/materialize.min.js"></script> </body>    here variable assigned php session variable. getting undefined when use $scope.something in controller file. controller file
var myapp = angular.module('myapp',[]); myapp.controller('restaurantcontroller',['$scope','$http', function($scope, $http){     $http.get($scope.something+'.json').success(function (data){         $scope.items = data;     });      $scope.process = function(item){         $scope.total = parseint($scope.total) + parseint(item.price);         item.added=true;     } }]);   the value of $scope.something undefined in controller file in php file getting correct value.
<body ng-app="myapp" ng-init="total=0;something='<?php echo $_session['rname'] ?>'">     <div ng-controller="restaurantcontroller"  class="container">         <div class="col l4 s4 container">         <label>search</label>    <input type="text" ng-model="search.name">     </div>         <div ng-repeat="item in items | filter:search" class="container">             <h3>{{item.name}}</h3>             <p>category:{{item.category}}</p>             <p>price:inr {{item.price}} /-</p>             <br/>             <button ng-hide="item.added"  ng-click="process(item)">add</button>             <button ng-show="item.added" class="ng-cloak">remove</button>         </div>         <h1>total:<span ng-model="total">{{total}}</span></h1>     </div>     <script src="../angular/app.js"></script>     <script src="../angular/restaurantcontroller.js"></script>     <script src="../materialize/js/materialize.min.js"></script> </body>    got solution. had change position of ng-init variables can e initialized page loads.
Comments
Post a Comment