I have a problem with getting data from MySQL database to angular $scope.
Here is my app.js
var mxscope = angular.module('mxscope', ['ui.router']);
mxscope.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/home');
$stateProvider
.state('stock', {
url: '/home',
templateUrl: 'views/stock.html',
controller: 'stockController'
})
});
mxscope.controller('stockController', function($scope, $http) {
$http.get('lib/getStockProducts.php')
.success(function(data) {
console.log(data);
$scope.products = data;
})
.error(function(){
console.log('error whatever');
})
});
If You look on the particular controllers there is one with http.get request And it doesn't seem to work: but I've found some strange behavior when testing it. The whole app is wrapped into .Electron app, and when I try the app the http.get request returns the code inside .php file.. Like so:
getStockProducts.php
<?php
include 'db.php';
$query="select * from sc_products";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
$arr = array();
if($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$arr[] = $row;
}
}
echo $json_response = json_encode($arr);
?>
with an dupes error :
Error: [ngRepeat:dupes] http://errors.angularjs.org/1.4.7/ngRepeat/dupes?p0=product%20in%20products&p1=string%3Ap&p2=p
But when I fire up the same app in browser window it works like charm, but it still returns duplicate result.
Any help ?