JavaScript Understanding $resource and controllers

I'm trying to understand the following pieces of code. If I understand correctly, below I have three resource objects that interact with REST server data sources (these objects are CategorySrv, ArticleSrv and SearchSrv respectively).

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');
});

Now, the question I'd like to ask if when is the controller's code executed? If I loaded the page, it would probably run only once. When will it run the next time? Controller's code doesn't run in a loop, but only when its methods are called from the view, or the portion of the page attached to this controller is loaded (AFAIK).

When this happens, the resource objects listed above are injected into the argument list and controller's function is called:

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;
});

Do I understand this correctly? Also, what's the difference between get and query above?

Answer:1

Hi I am new to react native and I am facing strange issue with routing. I am doing something wrong but need someone to guide me. index.android.js import { LandingScreen } from './src/components/...

Hi I am new to react native and I am facing strange issue with routing. I am doing something wrong but need someone to guide me. index.android.js import { LandingScreen } from './src/components/...

  1. route should declare a screen react native

I am enabling and disabling a div by checking two radio button (yes and no) but I am facing an issue when I am putting both id and class in same div and when I am using two div (one for id as parent ...

I am enabling and disabling a div by checking two radio button (yes and no) but I am facing an issue when I am putting both id and class in same div and when I am using two div (one for id as parent ...

  1. html same class name
  2. html same class different id
  3. html same class
  4. html div class same row
  5. html class name same as id
  6. html repeating same class

Is it possible to get the scroll event fired with onsen ? I tried to remove the onsen css file and it worked, the scroll event was fired. But that's no solution -.- I also tried the ons-scroller tag ...

Is it possible to get the scroll event fired with onsen ? I tried to remove the onsen css file and it worked, the scroll event was fired. But that's no solution -.- I also tried the ons-scroller tag ...

  1. onsen ui scroll event

I have the following jsfiddle example (check the console) and all you will see is [object Object] instead of person data: So, basically I have a vuejs instance and a div for v-for to iterate an ...

I have the following jsfiddle example (check the console) and all you will see is [object Object] instead of person data: So, basically I have a vuejs instance and a div for v-for to iterate an ...

  1. vuejs data return object
  2. vuejs computed return object