在config()模块中注入依赖项 - AngularJS
在config()模块中注入依赖项 - AngularJS
目前在app.js中,我有以下路由:
var gm = angular.module('gm', ['gm.services','gm.directives','gm.filters','gm.controllers','ngSanitize']); gm.config(['$routeProvider', 'Path', function($routeProvider, Path) { $routeProvider.when('/login', { templateUrl: Path.view('application/authentication/login.html'), controller: 'authController' }); $routeProvider.when('/dashboard', { templateUrl: Path.view('application/dashboard/index.html'), controller: 'dashboardController' }); $routeProvider.otherwise({ redirectTo: '/login' }); }]);
如你所见,我正在尝试注入Path依赖项。尽管我收到一个错误,说明找不到该提供程序。我认为这是因为配置模块提供程序在任何其他操作之前首先执行。以下是我在"services.js"中定义的Path提供程序的定义:
gm.factory("Path", function() { return { view: function(path) { return 'app/views/' + path; }, css: function(path) { return 'app/views/' + path; }, font: function(path) { return 'app/views/' + path; }, img: function(path) { return 'app/views/' + path; }, js: function(path) { return 'app/views/' + path; }, vendor: function(path) { return 'app/views/' + path; }, base: function(path) { return '/' + path; } } });
如何将此提供程序注入到配置模块中?