Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.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
Angular 角度数据绑定问题_Angular - Fatal编程技术网

Angular 角度数据绑定问题

Angular 角度数据绑定问题,angular,Angular,使用angular 1.6.6版本的数据绑定无法工作,尽管它从http get方法返回结果。您需要访问响应的数据属性,按如下方式更改控制器方法,并且$scope。employees是一个数组不是字符串 var myAPP = angular.module('myAPP', []); myAPP.controller('employeeCtrl', function ($scope, $http) { $scope.employees = ""; $http({

使用angular 1.6.6版本的数据绑定无法工作,尽管它从http get方法返回结果。

您需要访问响应的数据属性,按如下方式更改控制器方法,并且
$scope。employees
是一个
数组
不是
字符串

var myAPP = angular.module('myAPP', []);

myAPP.controller('employeeCtrl', function ($scope, $http) {    
    $scope.employees = "";
    $http({
        method: 'GET',
        url: '/Employee/GetEmployee'
    }).then(function (result) {
        $scope.employees = result;
    }, function (result) {
        console.log(result);
    }); 
});

您正在尝试遍历字符串。应该是

var myAPP = angular.module('myAPP', []);

myAPP.controller('employeeCtrl', function ($scope, $http) {    
    $scope.employees = [];
    $http({
        method: 'GET',
        url: '/Employee/GetEmployee'
    }).then(function (result) {
        $scope.employees = result.data;
    }, function (result) {
        console.log(result);
    }); 
});

但不是空字符串

然后
employees
成为HTTP响应。这又是一个你无法重复的东西。如果响应的主体确实是一个数组,那么它应该是

$scope.employees = null;

在问题中添加控制器代码也提供
employeeCtrl
$scope.employees = [];
$scope.employees = null;
$scope.employees = result.data;