【问题标题】:angularjs http get from json urlangularjs http 从 json url 获取
【发布时间】:2017-03-01 05:38:06
【问题描述】:

我对这段代码有疑问我有来自我的 asp.net web api 的 json 数据。我无法通过 angularjs 获取这些数据。如您所见,代码;

<!DOCTYPE html>
<html ng-app="myapp">
<head>
    <title ng-bind="helloAngular"></title>    
    <script src="~/Scripts/angular.min.js"></script>
        <script>
                var myapp = angular.module('myapp', []);
                myapp.controller('myController', function ($scope, $htpp){
                    $htpp.get({
                        method:'GET',
                        url:'http://localhost:50972/api/product'})
                        .success(function (response) {
                        $scope.result = response.statusText
                    });
                });
        </script>
    </head>
    <body ng-controller="myController">
        <table border="1">
                <tr ng-repeat="product in response">
                    <td>{{product.id}}</td>
                    <td>{{product.name}}</td>
                    <td>{{product.type}}</td>
                </tr>
            </table>
    </body>
    </html>

【问题讨论】:

  • 您得到什么错误或数据作为响应?你的 web api 代码在哪里查看你返回的内容?

标签: angularjs json asp.net-mvc asp.net-web-api


【解决方案1】:

您有一些拼写错误:而不是 $htpp 使用 $http

myapp.controller('myController', function ($scope, $http){
                    $http.get({
                        method:'GET',
                        url:'http://localhost:50972/api/product'})
                        .success(function (response) {
                        $scope.result = response.data;
                    });
                });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-10
    • 1970-01-01
    • 2016-08-13
    • 1970-01-01
    • 2015-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多