low*_*cks 2 javascript angularjs
我正在尝试在angularjs中开发模块化服务,这些服务可以在其他项目中使用,只需包含在根目录中(如angularjs,jquery ......).例如,我有匿名函数,如:
(function(ng, app) {
'use strict';
app.value('SomeValue', function(param1, param2) {
//code here
}
})(angular, app);
Run Code Online (Sandbox Code Playgroud)
我需要检查是否已在angularjs应用程序中定义此值(服务)并抛出错误(如果是).我在网上搜索了几个小时,也在Angularjs文档中搜索,在$ provide部分中它只是说如何注册.我试过这个,
$provide('SomeValue')
Run Code Online (Sandbox Code Playgroud)
要么
var checkForValue = function($provide){ //to inject the provide service
//and here is undefined
}
Run Code Online (Sandbox Code Playgroud)
要么
app.value('SomeValue'); //to see if this return something
Run Code Online (Sandbox Code Playgroud)
没有运气.