Im trying to load a JSON when app starts, and spread the data between all my controllers. I know this is not very hard to do, but Im confused from all articles/answers I've read because they use different syntax than I do, can someone Please direct me on how to to that?
Im currently making the controller make the $http.get :
myApp = angular.module("myApp", [])
myApp.controller "HomeCtrl", ($scope, $http, $routeParams) ->
$http.get('gethome.php').success (data) ->
$scope.home = data
But I have to repeat myself in each and every controller I want to have access to that Data
You can access to
$scope
with :After, you can init
data
in all your controllers.I will recommend you using Memoization pattern along with service and reuse the service in the controller
Pls check the below sample code