2014-01-12 39 views
2

我想在angularjs中开发模块化服务,可以在其他项目中使用,包括在根目录中(如angularjs,jquery ...)。比如我有匿名函数,如:如何检查价值服务是否已经定义angularjs

(function(ng, app) { 
    'use strict'; 

    app.value('SomeValue', function(param1, param2) { 
     //code here 
    } 

})(angular, app); 

我需要的是检查,如果这个值(服务)在angularjs应用已经定义并抛出错误,如果它是。我在网上搜索了几个小时,并在Angularjs文档中搜索,在$ provide部分中它只是说如何注册。我想这一点,

$provide('SomeValue') 

var checkForValue = function($provide){ //to inject the provide service 
    //and here is undefined 
} 

app.value('SomeValue'); //to see if this return something 

有没有运气可言。

回答

5

进样$injector为您服务,并呼吁:

$injector.has('SomeValue')