Angular 角度数据绑定问题
使用angular 1.6.6版本的数据绑定无法工作,尽管它从http get方法返回结果。您需要访问响应的数据属性,按如下方式更改控制器方法,并且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({
$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;