Where to make http request for every route in angularjs? -


suppose web app needs make http request site title, site description , on. since these variables common pages, makes sense request every time user enter site.

the question is, make calls? in run block? or create root controller these tasks?

you can use 1 of these 2 approaches:

  1. make call in run block , store value in $rootscope , use anywhere want,
  2. in states, use resolve page title , details , , in views , ease use resolve in root state , use resolved variable dependency in other child or sibling routes values..

        $stateprovider.state('root', {       resolve:{          // example using function simple return value.                 promiseobj:  function($http){         // $http returns promise url data         return $http({method: 'get', url: '/someurl'});       }     })    .state('sibling',{      controller:function($scope,promiseobj){       $scope.title = promiseobj.title;      }     }) 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -