title: Angular controller is not working with PHP and MySQLi
body: <p>I can't get my controller to work with PHP MySQLi.</p>
  
  <p>This is the body of my html document:</p>
  
  <pre><code>&lt;body class="nav-is-fixed" ng-app="myApp" ng-controller="productsCtrl"&gt;
  
  &lt;div id="cd-search" class="cd-search"&gt;
      &lt;form&gt;
          &lt;input type="search" ng-model="simpleFilter" placeholder="Pretraga ..."&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  
      &lt;!-- your content here --&gt;    
      &lt;div class="container" &gt;        
  
          &lt;section class="grid-wrap"&gt; 
  
              &lt;ul class="grid" id="grid"&gt; 
  
                  &lt;li ng-repeat="product in products | filter:simpleFilter"&gt;  
                      &lt;a href="#"&gt;&lt;img src="img/dummy.jpg" alt="dummy"&gt;&lt;h3&gt;{{ product.naziv }}&lt;/h3&gt;&lt;/a&gt;
                  &lt;/li&gt; 
  
              &lt;/ul&gt;
          &lt;/section&gt;
      &lt;/div&gt;&lt;!-- /container --&gt;
      &lt;!-- your content here --&gt;    
  
  
  &lt;!-- menu --&gt;
  &lt;script src="js/jquery-2.1.1.js"&gt;&lt;/script&gt;
  &lt;script src="js/jquery.mobile.custom.min.js"&gt;&lt;/script&gt;
  &lt;script src="js/main.js"&gt;&lt;/script&gt; 
  &lt;!-- menu --&gt;
  
  &lt;!-- include angular js --&gt;
  &lt;script src="js/angular/angular.min.js"&gt;&lt;/script&gt;
  &lt;!-- my angular js codes will be here --&gt;
  &lt;script src="js/angular/angular_controller.js"&gt;&lt;/script&gt;     
  &lt;!-- my angular js codes will be here --&gt;       
  </code></pre>
  
  <p></p>
  
  <p>This is a version of a controller that works, nothing fancy:</p>
  
  <pre><code>var app = angular.module('myApp', []);
      app.controller("productsCtrl",function($scope,$http){
  
          $scope.products = [
                              {naziv:'Livanjski sir'},
                              {naziv:'Livanjac'},
                              {naziv:'Trapist'},
                              {naziv:'Sunce'},
                              {naziv:'Koziji sir'},
                              {naziv:'Ovčiji sir'},
                              {naziv:'Dalmatinski sir'},
                              {naziv:'Delminium veliki kolut'},
                              {naziv:'Svježi sir'},
                              {naziv:'Delmato'},
                              {naziv:'Edamer'},
                              {naziv:'Gouda'},
                              {naziv:'Domaca livada'},
                              {naziv:'Domaci bijeli sir'},
                              {naziv:'Maslac'},       
                          ];  
  
      });  
  </code></pre>
  
  <p>But when I try to do this:</p>
  
  <pre><code>var app = angular.module('myApp', []);
    //app.controller('productsCtrl', ['$scope', function($scope){
      app.controller("productsCtrl",function($scope,$http){
  
          getProducts(); // Load all available productsks 
  
          function getProducts()
          {  
              $http.post("produkti.php").success(function(data)
                  {
                      $scope.products = data;
                  }
              );
          };      
  
      });  
  </code></pre>
  
  <p>This is the produkti.php document:</p>
  
  <pre><code> &lt;?php
  
  // Including database connections
  require_once '../resources/config.php';
  
      $query="select NAZIV from produkti";
      $result = $mysqli-&gt;query($query) or die($mysqli-&gt;error.__LINE__);
  
      $arr = array();
      if($result-&gt;num_rows &gt; 0) {
          while($row = $result-&gt;fetch_assoc()) {
              $arr[] = $row;  
          }
      }
  
      # JSON-encode the response
      echo $json_response = json_encode($arr);
  
  ?&gt;   
  </code></pre>
  
  <p>Just can't get it to work and can't find the error in my code.</p>