Angular $compile ui-grid for jasmine tests without $scope
Angular $compile ui-grid for jasmine tests without $scope
我正在尝试使用 $compile
编译一个 ui-grid 用于 Jasmine 测试。当我使用 $scope
作为控制器的可传递参数时,它工作正常。但是,我正在迁移到 vm
。这导致 $compile
在编译 ui-grid.
时失败
var rootScope = $rootScope;
var controller = $controller('Controller', {stuff: stuff, other: other});
$compile('<div ui-grid="vm.grids.grid1" ui-grid-selection ui-grid-auto-resize></div>')(rootScope);
rootScope.$apply();
当 ui-grid javascript 正在逐步执行时,这样做会给我一个 cannot read property 'data' of undefined.
的错误。
我也尝试过将控制器传递给 $compile,使用 controller.grids.grid1
代替 rootScope.$digest()
而不是 $apply()
。
我是不是遗漏了什么,或者我做错了?
好的,我找到了问题的答案。
This answer 在另一个问题上帮助我得到了答案。
var rootScope = $rootScope;
var controller = $controller(/**controller stuff**/);
rootScope.vm = controller;
$compile('html to compile')(rootScope);
rootScope.$apply();
有了这个,我可以在不使用 $scope
的情况下进行编译。
我正在尝试使用 $compile
编译一个 ui-grid 用于 Jasmine 测试。当我使用 $scope
作为控制器的可传递参数时,它工作正常。但是,我正在迁移到 vm
。这导致 $compile
在编译 ui-grid.
var rootScope = $rootScope;
var controller = $controller('Controller', {stuff: stuff, other: other});
$compile('<div ui-grid="vm.grids.grid1" ui-grid-selection ui-grid-auto-resize></div>')(rootScope);
rootScope.$apply();
当 ui-grid javascript 正在逐步执行时,这样做会给我一个 cannot read property 'data' of undefined.
的错误。
我也尝试过将控制器传递给 $compile,使用 controller.grids.grid1
代替 rootScope.$digest()
而不是 $apply()
。
我是不是遗漏了什么,或者我做错了?
好的,我找到了问题的答案。
This answer 在另一个问题上帮助我得到了答案。
var rootScope = $rootScope;
var controller = $controller(/**controller stuff**/);
rootScope.vm = controller;
$compile('html to compile')(rootScope);
rootScope.$apply();
有了这个,我可以在不使用 $scope
的情况下进行编译。