【发布时间】:2017-10-13 10:22:07
【问题描述】:
我正在使用以下代码并收到错误:Unresolved function or method then()。
我不知道这里出了什么问题。我正在使用 WebStorm 11。我在我的脚本。
这是我的控制器及以下:
RecordApp.controller('MyController',
['$scope','recordaccess',function($http,$route,$scope,recordaccess,
$location,$rootScope,$cookieStore) {
recordaccess.then(function(data) {------>Here I am getting error.
.
.
.
});
这是我用来从 JSON 中获取数据的:
RecordApp.factory('recordaccess', ['$http', function($http) {
return $http.get('record1.json')
.then(function successCallback(response) {------>Here I am getting error.
return response.data;
},
function errorCallback(response) {
alert("Error occurred. Status: " +
response.status + " - " + response.statusText);
});
}]);
【问题讨论】:
-
注入列表与函数参数不匹配。试试 ['$http', '$route', '$scope','recordaccess','$location','$rootscope','$cookieStore',function($http,$route,$scope,recordaccess , $location,$rootScope,$cookieStore)
-
@atao 我试过用这个但没有运气。