Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 网页中未显示任何内容,且角度清晰地显示数组中的数据_Javascript_Asp.net_Angularjs_Arrays_Ajax - Fatal编程技术网

Javascript 网页中未显示任何内容,且角度清晰地显示数组中的数据

Javascript 网页中未显示任何内容,且角度清晰地显示数组中的数据,javascript,asp.net,angularjs,arrays,ajax,Javascript,Asp.net,Angularjs,Arrays,Ajax,不确定发生了什么,但我无法在使用ng repeat with template的网页上显示任何内容 这是显示数据的图片图像 不知道为什么不直接显示在网页上 Devices: Array[17] 0 : Object Aid : "....." ... 1 : Object 带功能的角度控制器 (function () { 'use strict'; angular.module('app').controller('DeviceController'

不确定发生了什么,但我无法在使用ng repeat with template的网页上显示任何内容

这是显示数据的图片图像

不知道为什么不直接显示在网页上

Devices:  Array[17] 
  0 : Object
    Aid :  "....."
    ...
  1 : Object 
带功能的角度控制器

(function () {
  'use strict';

  angular.module('app').controller('DeviceController', DeviceController);

        function DeviceController($http){
            var vm = this;
            var dataService = $http;
            //dataService.get("/api/Product")

            vm.devices = [];

        deviceList();

        function deviceList() {
            dataService.get("http://localhost:42822/api/device")
            .then(function (result) {
                vm.devices = result.data;
                //debugger;
                console.log(vm.devices);
            },
            function (error) {
                handleException(error);
            });
        }


        function handleException(error) {
            alert(error.data.ExceptionMessage);
        }

  }



 })(); 
HTML

<html>

<head> </head>

<body>
    <div ng-app="app" ng-controller="DeviceController as vm">
            <div>test</div><br>

        <table>
            <tbody>
                <tr ng-repeat="device in vm.devices">
                    <td>{{device.Aid}}</td>
                    <td>{{device.DeviceId}}</td>
                </tr>
            </tbody>
        </table>


    </div>
</body>

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js"></script>

<!--<script src="~/Scripts/angular.min.js"></script>-->
<script src="./app/app.module.js"></script>
<script src="./app/device.controller.js"></script>



</html>

测试
{{device.Aid} {{device.DeviceId}

不知道为什么不直接显示在网页上

由于响应对象的
设备中有数据,因此需要更改ajax解析中的赋值,如下所示

Devices:  Array[17] 
  0 : Object
    Aid :  "....."
    ...
  1 : Object 
vm.devices = result.data.Devices;
我建议您更改服务器上的响应,而不是在
Devices
对象中发送
Devices
集合,而是直接发送响应


您也可以直接对HTML进行更改,但这不是一个好办法

<tr ng-repeat="device in vm.devices.Devices">
    <td>{{device.Aid}}</td>
    <td>{{device.DeviceId}}</td>
</tr>

{{device.Aid}
{{device.DeviceId}

不错!成功了。1.这对我来说很难看,这是标准还是我应该在代码中修改一些东西来解决这个问题,再次感谢大家much@CodingAway如果您在响应中直接返回
Devices
collection,那就太棒了。好的,等等,它“与vm.devices.devices一起工作,但我没有更改为具有result.data.devices-如果我更改为result.data.devices,那么我可以只在vm.devices中执行设备吗?@CodingAway是的,这就是为什么我在这两种方式之间使用分隔符,第一种方式是合适的。”。。不要去第二个(它只是为了演示)好的,thx这么多-真的很快,。。这些数据来自Web Api服务调用,那么如何在我的终端(客户端)上实现这一点呢?“如果在响应中直接返回设备集合…”是否必须在服务器端执行此操作?谢谢