Trying to create a custom provider and use it during application setup. At the setup stage, the error "The module application could not be created due to an unknown provider" configRoutesProvider. "Supplier code:
(function () {
'use strict';
angular.module('app-routing', [])
.provider('configRoutesProvider', function () {
this.$get = ['$http', getRoutesProvider];
function getRoutesProvider($http) {
return {
getRoutes: function ($http) {
return $http.get('https://localhost:44311/api/account/routes').then(function (results) {
return results;
});
}
};
}
});
}).call(this);
In the app.js code, get a link to the "app-routing" module:
(function () {
'use strict';
var app = angular.module('app',
[
'ngRoute',
'LocalStorageModule',
'app-routing'
]);
app.run();
})();
And in config.js, when you try to contact the provider, you get the above error:
app.config(['$routeProvider', 'configRoutesProvider', routeConfigurator]);
function routeConfigurator($routeProvider, configRoutesProvider) {
var routes = configRoutesProvider.getRoutes();
routes.forEach(function (r) {
$routeProvider.when(r.href, {
controller: r.controller,
templateUrl: r.templateUrl
});
});
$routeProvider.otherwise({ redirectTo: '/home' });
}
In index.html, the script registration order is as follows:
<script src="app/routesProvider.js"></script>
<script src="app/app.js"></script>
<script src="app/config.js"></script>
Can't figure out what I missed?
source
share