My application has multiple screens and controllers that rely on data from servers. I want to use the router resolve functionality to ensure that all data dependencies are resolved before rendering the screen. However, I am facing an issue with the example provided below. Can you help me understand why it is not working properly?
angular.module('app',['ngRoute'])
.service('Data1', function ($q, $routeProvider, $http) {
var self = this;
this.fetch = function() {return $http.get('/json/data1',{id:$routeProvider.id})}
}
.service('Data2', function ($q, $routeProvider, $http) {
var self = this;
this.fetch = function() {return $http.get('/json/data2',{id:$routeProvider.id})}
}
.config(function($routeProvider){
§routeProvider.when('/:id',{
controller:'TestCtrl',
templateUrl:'template.html',
resolve: {
data1: function (Data1) { return Data1.fetch(); },
data1: function (Data2) { return Data2.fetch(); }
}
});
})
.controller('TestCtrl', function($location, $routeParams, $http, data1,data2) {
console.log(data1);
console.log(data2);
});