Getting data from a web service with Angular.js

前端 未结 4 1733
孤城傲影
孤城傲影 2020-12-29 00:13

Im trying to get data in a Json format from a remote WS using Angular and im having some trouble. The data comes from the web service correctly but i cant use it inside the

4条回答
  •  佛祖请我去吃肉
    2020-12-29 00:47

    Instead of using a run block you can use your $http service inside the controller, then attach your data to the scope like normal. Just remember to inject the $http service into your controller.

    app.controller('booksCtrl', function ($scope, $http) { 
        $http.get("https://whispering-woodland-9020.herokuapp.com/getAllBooks").success(function (data) {
            $scope.booksJson = data;
        });
    });
    

提交回复
热议问题