I\'m getting to know AngularJS and I have an interesting problem. I\'m getting to know the routeProvider and I thought I could write my app like if you search a table name,
try this:
tables: function($http, $routeParams, $rootScope){
var promise = $http.get('http://mywebsite.com/doc/ajax/table.php?function=get_table_data&table='+$routeParams.table)
.then(function(response){
console.log($routeParams.table);
return response.data;
});
if($rootScope.$$phase != '$apply' && $rootScope.$$phase != '$digest') {
$rootScope.$apply();
}
return promise;
}
From $routeParams docs:
Note that the $routeParams are only updated after a route change completes successfully. This means that you cannot rely on $routeParams being correct in route resolve functions. Instead you can use $route.current.params to access the new route's parameters.
So just inject $route
instead of $routeParams
:
resolve: {
tables: function($http, $route){
return $http.get('http://mywebsite.com/doc/ajax/table.php?function=get_table_data&table='+$route.current.params.table)
.then(function(response){
return response.data;
})
}
}