javascript - Angular 1.6提示$http.get(...).success is not a function
本文介绍了javascript - Angular 1.6提示$http.get(...).success is not a function的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
学习Angular的Http时总是遇到$http.get(...).success is not a function的报错。
非常简短的代码:
angular.module('myApp',[])
.controller('C1', function ($scope, $http) {
$http.get("data/data.php")
.success(function () {
console.log('链接成功!');
});
});
控制台提示:
angular.min.js:122TypeError: $http.get(...).success is not a function
at new <anonymous> (02.html:32)
at Object.invoke (angular.min.js:43)
at R.instance (angular.min.js:93)
at n (angular.min.js:68)
at g (angular.min.js:60)
at g (angular.min.js:61)
at angular.min.js:60
at angular.min.js:21
at m.$eval (angular.min.js:147)
at m.$apply (angular.min.js:148)
data.php只是一个JSON文件,希望得到大神们的帮助。:)
解决方案
看文档 https://docs.angularjs.org/ap...$http 吧
新版本的angular中取消了success 和 error方法。
用promise吧
$http.get("data/data.php")
.then(function (res) {
console.log('链接成功!');
})
.catch(err => console.log(err))
这篇关于javascript - Angular 1.6提示$http.get(...).success is not a function的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文