2016-12-27 110 views
1

我试图使用下面的代码解析json,但它显示一个空白页。

var app = angular.module('myApp', []); 
app.controller('myCtrl', function($scope, $http) { 
    $http.get("http:krispypapad.herokuapp.com/fetch_article").success(function (response) { 
     $scope.myWelcome = data.response; 

    }); 
}); 
+0

参见[为什么角$ HTTP成功/错误的方法已过时?从v1.6中删除?](http://stackoverflow.com/a/35331339/5535245)。 – georgeawg

回答

1

我认为有错字与正在使用的网址:

http:krispypapad.herokuapp.com代替http://krispypapad.herokuapp.com你缺少几个//

这是你的代码将如何看起来像:

var app = angular.module('myApp', []); 
app.controller('myCtrl', function($scope, $http) { 
    $http.get("http://krispypapad.herokuapp.com/fetch_article").success(function (response) { 
     $scope.myWelcome = response; //<-- no .data is required 

    }); 
}); 
+0

'.success'方法不返回响应对象。改为使用'.then'方法。 – georgeawg

0

您在网址中有错字,它应该是这样的:

http://krispypapad.herokuapp.com/whatever 

而且你应该使用response.datadata.response

+0

'.success'方法不返回响应对象。改为使用'.then'方法。 – georgeawg