TypeError:无法调用方法'获取'的未定义
TypeError: Cannot call method 'get' of undefined
我使用AngularJs和Protractor测试api数据,并尝试使用restapi从服务器获取响应,然后在控制台上显示这些数据
Bellow是我的密码
我的服务文件:
module.exports = {getResponse : function ($http){
$http.get('http://echo.jsontest.com/title/ipsum/content/blah').
success(function(data, status, headers, config) {
console.log(data)
var jsonData = JSON.stringify(data);
console.log(jsonData);
// this callback will be called asynchronously
// when the response is available
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
}
};
测试用例文件:
var helper = require('./helper');
describe('A test suite', function() {
it('does something to myService', function() {
var result = helper.getResponse();
console.log(result);
});
});
提前感谢。。。
您的服务模型中包含$http
了吗?
angular.module('app').service('YourService', ['$http', function($http) {
// your code
}]);
相关文章:
- 无法获取属性'selectedIndex'的未定义引用或null引用
- 无法获取属性'Id'使用Knockout.js的未定义或空引用API
- 骨干's Router.execute(callback,args,name)方法获取未定义的名称
- JavaScript-获取数据属性的值返回未定义的值
- Microsoft JScript运行时错误:无法获取属性'的值;样式':对象为null或未定义
- 无法获取属性'字符串'的未定义或null引用IE 11 ASP.NET
- 获取结果未定义(主干.js)
- SCRIPT5007:无法获取属性'长度'的未定义引用或null引用
- 获取“;无法读取属性'[方法]'“未定义”;
- 无法获取属性'setActionableButtonState'的未定义引用或null引用
- Google Script var获取未定义的值
- Jquery从JSON获取数据(未定义)
- 获取 无法读取未定义的引导轮播脚本的属性“偏移宽度”
- 无法获取未定义或空引用的属性“new_textholder”
- 在 JavaScript 对象中添加子对象时获取“无法设置未定义的属性'项目'”
- 在 javascript 中使用它获取未定义的设置对象的属性值
- 未定义获取 jquery 错误 $
- javascript:未定义获取对象
- 未定义获取输出而不是对象属性
- 未定义获取$parse的angular指令