简体   繁体   English

如何获得模块中定义的angularjs控制器的引用?

[英]How do you get a reference to an angularjs controller defined in a module?

I have a jasmine test and I can't get a reference to the controller constructor function as it was defined in a module. 我有一个茉莉花测试,我无法获得对模块中定义的控制器构造函数的引用。 See my gist here https://gist.github.com/hcabnettek/5222429 请参阅我的要点https://gist.github.com/hcabnettek/5222429

I need to unit test a controller defined like 我需要对像这样定义的控制器进行单元测试

angular.module('foo', []).controller('fooCtrl', function($scope){ $scope.foo = 'bar'; });

Can anyone possibly help me out? 有人可以帮帮我吗? Thanks! 谢谢!

http://www.itaware.eu/2012/10/19/angularjs-unit-tests-and-end-to-end-tests/ http://www.itaware.eu/2012/10/19/angularjs-unit-tests-and-end-to-end-tests/

The key was the module() function in angular-mocks. 关键是角度模拟中的module()函数。 Now it works using the string controller name as defined inside the module. 现在它使用模块内定义的字符串控制器名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从AngularJS控制器,如何解析模块中定义的另一个控制器功能(动态ng-controller)? - From an AngularJS controller, how do I resolve another controller function defined in the module (dynamic ng-controller)? 如何在angularJS中获得对指令对象实例的引用? - how do you get a reference to the directive object instance in angularJS? 如何用茉莉花测试在IIFE中定义的angularjs模块? - How to you test an angularjs module defined inside an IIFE with jasmine? AngularJS-如何在一个模块中定义的控制器中使用在一个模块中定义的服务 - AngularJS - How to use services which are defined in one module, in the controller defined in another module angularjs控制器模块参考加载空白页 - angularjs controller module reference loads blank page AngularJS控制器到底是如何定义的? - How exactly is an AngularJS controller defined? AngularJS - 如何在控制器内获取ngRepeat过滤结果引用 - AngularJS - how to get an ngRepeat filtered result reference inside controller AngularJS-编译html后如何通过路径关联控制器? - AngularJS - how do you associate a controller by path after compiling the html? 如何访问AngularJs控制器中的路由参数 - How do you access route parameters in an AngularJs Controller 如何将条件服务注入AngularJS 1 Controller - How do you inject a condition service into AngularJS 1 Controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM