Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在angularJS中的全局名称空间中确定控制器_Javascript_Angularjs_Unit Testing_Angularjs Scope - Fatal编程技术网

Javascript 如何在angularJS中的全局名称空间中确定控制器

Javascript 如何在angularJS中的全局名称空间中确定控制器,javascript,angularjs,unit-testing,angularjs-scope,Javascript,Angularjs,Unit Testing,Angularjs Scope,为了在下面的单元测试中用模拟范围对象实例化我的控制器,我需要确保我的控制器在全局namesapce上可用 describe('testCtrl', function(){ it('should create "phones" model with 3 phones', function() { var scope = {}, ctrl = new testCtrl(scope); expect(scope.phones.length).toBe(3);

为了在下面的单元测试中用模拟范围对象实例化我的控制器,我需要确保我的控制器在全局namesapce上可用

describe('testCtrl', function(){

  it('should create "phones" model with 3 phones', function() {
    var scope = {},
        ctrl = new testCtrl(scope);

    expect(scope.phones.length).toBe(3);
  });

});

但是,如何确定angularJS中的全局名称APCE中是否有控制器?

一个简单的示例,根模块
app
中的控制器应位于全局名称空间中,依赖模块
产品
中的控制器应为非全局控制器

angular.module('app'[
"产品",,
...

]);

测试类型Ctrl!=未定义,实际上控制器只是一个javascript函数测试似乎很奇怪…您将帮助文档:您可以在整个应用程序中访问“app”模块内的“products”控制器,但您必须在应用程序顶部声明“app”模块。