$http.get('api/url-api')
.success(function (data, status, headers, config){console.log(0)}
angular1.x中,$http的success方法,在换项目的时候发现报错,$http.get(…).success is not a function,查了之后发现:
.success方法在angluar1.6中已经不再使用,需要改为then方法
app.controller('MainCtrl', function ($scope, $http){
$http({
method: 'GET',
url: 'api/url-api'
}).then(function (success){
},function (error){
});
}
在success和error方法中使用定义callback方法。使用Promise规则
另外angular1.6中,url也从”#”变为了”#!”hashbang的格式。
Due to aa077e8, the default hash-prefix used for $location hash-bang URLs has changed from the empty string ('') to the bang ('!'). If your application does not use HTML5 mode or is being run on browsers that do not support HTML5 mode, and you have not specified your own hash-prefix then client side URLs will now contain a ! prefix. For example, rather than mydomain.com/#/a/b/c the URL will become mydomain.com/#!/a/b/c.
说点什么
欢迎讨论