I am currently working on deciphering the code snippets below. From what I gather, there are three resource objects - CategorySrv
, ArticleSrv
, and SearchSrv
that interact with REST server data sources.
app.factory('CategoryService', function($resource) {
return $resource('categories');
});
app.factory('ArticleService', function($resource) {
return $resource('articles');
});
app.factory('SearchService', function($resource) {
return $resource('articles/search');
});
My question is: when does the controller's code execute? It seems like it only runs once when the page loads. When will it run again? As far as I know, the controller's code doesn't run in a loop but is called either when its methods are invoked from the view or when the section of the page associated with this controller is loaded.
When triggered, the listed resource objects are passed as arguments and the controller's function is executed:
app.controller('AppCtrl', function($scope, $location, CategoryService, ArticleService, CartService) {
CategoryService.query(function(response) {
$scope.categories = response;
});
ArticleService.query(function(response) {
$scope.articles = response;
});
CartService.get(function(response) {
$scope.cartInfo = response;
});
Am I interpreting this correctly? And could you explain the difference between using get
and query
in the above context?