首页 新闻 搜索 专区 学院

angular测试问题

0
悬赏园豆:50 [已解决问题] 解决于 2014-10-08 16:06

在项目中新写了一个service文件A。在A中有一个

var pageApp = angular.module('Pagination', []);

pageApp.factory('nameConverter', ['$http', function ($http) {

}]);

在controller中注入nameconverter。 

在测试时,SpecRunner一直 Unknown provider: nameConverterProvider。

要怎么处理 才能让specrunner找到他,现在测试停在这里了。

战马的主页 战马 | 初学一级 | 园豆:27
提问于:2014-10-08 15:48
< >
分享
最佳答案
0

你的controller是在那个模块中呢?如果是一个新的模块,那么需要让controller的模块,依赖于模块"Pagination"。

angular.module('Test1',['Pagination'])
.controller('xxx',['nameConverter',function(nameConverter){
    //do something...
}]);
收获园豆:50
幻天芒 | 高人七级 |园豆:36662 | 2014-10-08 15:59

1为controller  

2为新加服务

3是按你说的加了

但是还是不行。测试还是报错

Error: [$injector:modulerr] Failed to instantiate module app.audit due to: Error: [$injector:nomod] Module 'app.audit' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument. http://errors.angularjs.org/1.2.3/$injector/nomod?p0=app.audit at http://localhost:8088/Scripts/vendor/angular.js:78:12 at http://localhost:8088/Scripts/vendor/angular.js:1522:17 at ensure (http://localhost:8088/Scripts/vendor/angular.js:1447:38) at module (http://localhost:8088/Scripts/vendor/angular.js:1520:14) at http://localhost:8088/Scripts/vendor/angular.js:3549:22 at Array.forEach (native) at forEach (http://localhost:8088/Scripts/vendor/angular.js:300:11) at loadModules (http://localhost:8088/Scripts/vendor/angular.js:3543:5) at Object.createInjector [as injector] (http://localhost:8088/Scripts/vendor/angular.js:3483:11) at workFn (http://localhost:8088/Scripts/vendor/angular-mocks.js:2096:52) http://errors.angularjs.org/1.2.3/$injector/modulerr?p0=app.audit&p1=Error%3A%20%5B%24injector%3Anomod%5D%20Module%20'app.audit'%20is%20not%20available!%20You%20either%20misspelled%20the%20module%20name%20or%20forgot%20to%20load%20it.%20If%20registering%20a%20module%20ensure%20that%20you%20specify%20the%20dependencies%20as%20the%20second%20argument.%0Ahttp%3A%2F%2Ferrors.angularjs.org%2F1.2.3%2F%24injector%2Fnomod%3Fp0%3Dapp.audit%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8088%2FScripts%2Fvendor%2Fangular.js%3A78%3A12%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8088%2FScripts%2Fvendor%2Fangular.js%3A1522%3A17%0A%20%20%20%20at%20ensure%20(http%3A%2F%2Flocalhost%3A8088%2FScripts%2Fvendor%2Fangular.js%3A1447%3A38)%0A%20%20%20%20at%20module%20(http%3A%2F%2Flocalhost%3A8088%2FScripts%2Fvendor%2Fangular.js%3A1520%3A14)%0A%20%20%20%20at%20http%3A%2F%2Flocalhost%3A8088%2FScripts%2Fvendor%2Fangular.js%3A3549%3A22%0A%20%20%20%20at%20Array.forEach%20(native)%0A%20%20%20%20at%20forEach%20(http%3A%2F%2Flocalhost%3A8088%2FScripts%2Fvendor%2Fangular.js%3A300%3A11)%0A%20%20%20%20at%20loadModules%20(http%3A%2F%2Flocalhost%3A8088%2FScripts%2Fvendor%2Fangular.js%3A3543%3A5)%0A%20%20%20%20at%20Object.createInjector%20%5Bas%20injector%5D%20(http%3A%2F%2Flocalhost%3A8088%2FScripts%2Fvendor%2Fangular.js%3A3483%3A11)%0A%20%20%20%20at%20workFn%20(http%3A%2F%2Flocalhost%3A8088%2FScripts%2Fvendor%2Fangular-mocks.js%3A2096%3A52)

战马 | 园豆:27 (初学一级) | 2014-10-08 16:03

@战马: 写法有误哈,你注意看依赖模块,是字符串类型的。

幻天芒 | 园豆:36662 (高人七级) | 2014-10-08 16:05

@幻天芒: 谢谢 。  大神就是大神!!

战马 | 园豆:27 (初学一级) | 2014-10-08 16:06

@战马: :),额,恰好用的这个...

幻天芒 | 园豆:36662 (高人七级) | 2014-10-08 16:08

@幻天芒: http://q.cnblogs.com/q/66405/

 可以帮忙看看吗 ?

战马 | 园豆:27 (初学一级) | 2014-10-09 09:07

@战马: 额,我先看看~

幻天芒 | 园豆:36662 (高人七级) | 2014-10-09 10:06
其他回答(1)
0

这个问题处理了吗?我也遇到这样的问题吧,把’use strict‘注释掉就可以

roberg | 园豆:204 (菜鸟二级) | 2014-12-28 12:58
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册