3

我的问题与定义像 angular.module('myApp').controller( 的测试 Angular 控制器非常相似。我想我不会劫持这个问题,而是单独问我的问题。当我使用以下表格的建议答案时:

describe('evCalcApp controllers', function(){
  beforeEach(module('evCalcApp.controllers'));
    var scope, ctrl
    beforeEach(inject(function($controller, $rootScope) {
      scope = $rootScope.$new();
      ctrl = $controller('MyMileageCalcController', {$scope: scope});
    }));

这适用于第一个控制器。但是,如果您在同一个文件中测试多个控制器,您将如何注入第二个控制器(让我们称之为它MyCtrl2)?

4

1 回答 1

3

和上一个一样

describe('evCalcApp controllers', function(){
  beforeEach(module('evCalcApp.controllers'));
    var scope, ctrl, ctrl2;
    beforeEach(inject(function($controller, $rootScope) {
      scope = $rootScope.$new();
      scope2 = $rootScope.$new();
      ctrl = $controller('MyMileageCalcController', {$scope: scope});
      ctrl2 = $controller('MyCtrl2', {$scope: scope2});
    }));
于 2013-07-10T21:16:52.723 回答