2013-06-25 33 views
3

我有一个名为TestProvider注入提供商到一个模块配置

我想配置我的提供商我的模块供应商。

这工作:

app.config(function(testProviderProvider){ 
    // ... 
} 

这工作不是:

app.config(function(testProvider){ 
    // ... 
} 

我注入相同的供应商到控制器,它的工作原理:

function TestCtrl($scope,testProvider){ 
    // .. 
} 

跆拳道?

回答

1

来自官方的文档:

提供商(名称,供应商)

Register a provider for a service. The providers can be retrieved and can have additional configuration methods. 

Parameters 
name – {string} – The name of the instance. NOTE: the provider will be available under name + 'Provider' key. 

您应该为您的供应商没有 “商” 字。 此代码正常工作:

myApp.provider('test', function() { 

}); 

myApp.config(function (testProvider) { 

}); 
+0

我发现令人困惑。但是,我应该更好地阅读文档。感谢你付出的努力。 – Sprottenwels