1

I'm trying to display a row count from a php file in AngularJS

php

//count.php output displays 1500
echo json_encode($total);

angular

//navigationController.js
angular
  .module('theme.core.navigation_controller', ['theme.core.services'])
  .controller('NavigationController', ['$scope', '$location', '$timeout', function($scope, $location, $timeout) {
    'use strict';
    $scope.menu = [{
      label: 'Overview',
      iconClasses: '',
      separator: true
    }, {
      label: 'Home',
      iconClasses: 'glyphicon glyphicon-home',
      url: '#/'
    }, {
      label: 'Clients',
      iconClasses: 'glyphicon glyphicon-th-list',
      html: '<span class="badge badge-warning">**1500**</span>',
      url: '#/clients'
    }, {
      label: 'Map',
      iconClasses: 'glyphicon glyphicon-map-marker',
      url: '#/map'
    }];

How do I pass the count to the angularjs file and display it instead of the 1500 in the angularjs file?

1
  • I am new to this site. I tried to bold the 1500 in the code for the js file. Commented Jun 12, 2015 at 13:57

2 Answers 2

2

You can use $http and make a request to your php file and get the count.

Add this code into your controller

$http.get('url to count.php').then(function (count) {
   $scope.count = count
})

In the markup

<div class="bold">{{count}}</div>

Add this css into your css file

.bold {
   font-weight: bold;
}

If you have a lot of backend transactions performed on the page then it is better you use angularjs services.

Angular references : $http services

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

Comments

1

You should really be using a dataFactory as a service to interact between the backend PHP and the front end AngularJS

http://weblogs.asp.net/dwahlin/using-an-angularjs-factory-to-interact-with-a-restful-service

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.