I tried to look around and I found more questions that look the same to this one but no one done it the way I do it, for some reason it doesn't work...
here is the angular code,
var myAPP = angular.module('myAPP', ['ngTable']);
myAPP.run(function($rootScope, $http, $moment) {
$rootScope.items = [];
$rootScope.currentEvent = "";
// inital stats - items
$http.get("/wp-content/themes/theme/myjson.php", {
params: {
getAll: true,
watcherID: <?=get_current_user_id()?>
}
}).then(function(reponse) {
$rootScope.items = reponse.data;
});
$rootScope.update = function(inital) {
$rootScope.items = [];
$http.get("/wp-content/themes/theme/myjson.php", {
params: {
sort: true,
watcherID: <?=get_current_user_id()?>,
event: $rootScope.currentEvent
}
}).then(function(response) {
$rootScope.items = response.data;
console.log("data", $rootScope.currentEvent, $rootScope.items);
});
} // end update
$rootScope.$watch('items', function(newValue, oldValue) {
if(!newValue) return;
if(newValue != oldValue) {
$rootScope.items = newValue;
console.log('new value $rootScope.items', $rootScope.items);
}
});
});
myAPP.controller('tbleCtrl', function($scope, $rootScope, $http, ngTableParams) {
$scope.data = $rootScope.items;
$rootScope.$watch('items', function(newValue, oldValue) {
if(!newValue) return;
if(newValue != oldValue) {
$scope.data = $rootScope.items;
}
});
});
first I tried to use the rootScope to handle stuff but after that I tried also to put it in a scope (I thought it i'd make the difference to put the values on var named data as all the examples) but I had no luck wit that also.
and this is my controller
<div ng-controller="tbleCtrl">
<table ng-table show-filter="true" class="floodPostTable">
<tr>
<th sortable="number">number</th>
<th sortable="roadNumber">Road number<br /></th>
</tr>
<tr ng-repeat="item in data">
<td><div ng-show="item.number != false">{{ item.number }}</div></td>
<td><div ng-show="item.roadNumber != false">{{ item.roadNumber }}</div></td>
</tr>
</table>
</div>
if anyone can direct me what I am missing or what I'm doing wrong I'd be very thankful for it!
PS: the table is shown and its working fine with the implement the repeat but only the sorting doesn't work for some reason.