0

Can anyone please suggest whats the best way to send data to the routed view using angular-route module.

I have tried using resolve block but there are like 500 route configuration in my project and since similar kind of data needs to be passed, it would be better if we can have some common resolve block or some other logic by which we can pass the data to the routed view instead of modifying 500 routes and add the same logic repeatedly.

I tried passing value in resolve block but this will mean modifying the route configuration for all 500 routes

// route configuration for adding resolve block

$routeProvider.when('/classes/:classId', {
    controller: 'ClassCtrl',
    templateUrl: TEMPLATE_CACHE + '/classByStudent.html',
    reloadOnSearch: false,
    resolve: {
        data: 'some_value' 
    }
})
Roy Bogado
  • 4,299
  • 1
  • 15
  • 31
ckgupta
  • 41
  • 7
  • Why don't you use $rootScope to save data and access data globally or you can create a service and then access that service from controller because ultimately in route config you will pass data will be resolved from Controller ! – Abu Sufian May 27 '19 at 10:18
  • 1
    You can also create a service or factory and set the data into it. Use this data wherever you want. Just inject it into the controller and access the data. See here: https://stackoverflow.com/questions/29769804/getting-and-setting-value-in-factory-in-angualrjs – Harshad May 27 '19 at 12:29
  • thanks for the suggestions, may be I dint explain the problem completely. Basically, I need to send information based on different routes configured (i.e., different value for different routes) to the routed page. – ckgupta May 27 '19 at 13:09
  • Possible duplicate: https://stackoverflow.com/questions/19937751/angular-how-use-one-resolve-for-all-the-routes-of-my-application – amarmishra May 28 '19 at 04:37

0 Answers0