itachi itachi - 1 year ago 145
Javascript Question

AngularJS custom provider causing "Unknown provider" exception

I have created a custom provider in AngularJS, which is supposed to be an application global configuration. Unfortunately, I am not able to inject this provider, because AngularJS throws "Unknown provider" exception. I have totally no idea what is wrong with my code.


(function () {
'use strict';

angular.module('app', [

configuration.$inject = ['ConfigProvider'];

function configuration(ConfigProvider) {


(function () {
'use strict';

.provider('ConfigProvider', ConfigProvider);

ConfigProvider.$inject = [];

function ConfigProvider() {
var config = [];

var provider = {
$get: $get,
setFoo: setFoo,

return provider;

function $get() {
return {
getConfig: function () {
return config;

function setFoo(foo) {
config['foo'] = foo;

config-provider.js is loaded first in my scripts file, but changing the order does not change the behavior anyway - still "Unknown provider". Any help will be appreciated.

Answer Source

You should declare the provider without 'Provider' suffix:

module.provider('Config', ConfigProvider);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download