Possibly unhandled rejection: error
来源:6-5 用户模块逻辑编写-使用表单校验

星空下的仓颉
2017-12-14
老师,请帮我指正一下这个报错,谢谢!
这是http.js
'use strict'; angular.module('app').config(['$provide', function($provide){ $provide.decorator('$http', ['$delegate', '$q', function($delegate, $q){ $delegate.post = function(url, data, config) { var def = $q.defer(); $delegate.get(url).then(function(res){ def.resolve(res); },function(err){ def.reject(err); }); return { success: function(cb){ def.promise.then(cb); }, error: function(cb) { def.promise.then(null, cb); } } } return $delegate; }]); }]);
这是registerCtrl.js
'use strict'; angular.module('app').controller('registerCtrl',['$interval','$http','$scope','$state',function($interval,$http,$scope,$state){ $scope.submit = function(){ $http.post('data/regist.json',$scope.user).then(function successCallback(res){ console.log(res.data); },function errCallback(err){ console.log(err); }); } var count = 60; $scope.send = function(){ $http.get('data/code.json').then(function successCallback(res){ if(1 === res.data.state){ count = 60; $scope.time = '60s'; var interval = $interval(function(){ if(count <=0){ $interval.cancel(interval); $scope.time = ''; }else{ count --; $scope.time = count + 's'; } },1000); } }); } }]);
以下是浏览器报错截图
我已经用的是then的方法发起请求的,不明白哪里出了问题,望老师看下,谢谢1
写回答
2回答
-
页面功能正常吗?
好像这是validation模块和angular1.6才会出现的错误~可能不是你的代码问题
012017-12-15 -
星空下的仓颉
提问者
2017-12-15
然后纠结这个部分:
httpjs中: get(url).then这里我用的是then方法,
'use strict'; angular.module('app').config(['$provide', function($provide){ $provide.decorator('$http', ['$delegate', '$q', function($delegate, $q){ $delegate.post = function(url, data, config) { var def = $q.defer(); $delegate.get(url).then(function(res){ def.resolve(res); },function(err){ def.reject(err); }); return { success: function(cb){ def.promise.then(cb); }, error: function(cb) { def.promise.then(null, cb); } } } return $delegate; }]); }]);
registerjs中我用的是success方法,我改成then方法会报错,1.6版本的不是可以支持then方法废除success和erro方法了吗?这里为何必须用成success才可以,望老师抽空解答下,感谢!
'use strict'; angular.module('app').controller('registerCtrl',['$interval','$http','$scope','$state',function($interval,$http,$scope,$state){ $scope.submit = function(){ $http.post('data/regist.json',$scope.user).success(function(res){ console.log(res.data); }); } var count = 60; $scope.send = function(){ $http.get('data/code.json').then(function successCallback(res){ if(1 === res.data.state){ count = 60; $scope.time = '60s'; var interval = $interval(function(){ if(count <=0){ $interval.cancel(interval); $scope.time = ''; }else{ count --; $scope.time = count + 's'; } },1000); } }); } }]);
012017-12-15
相似问题