我正在使用angularjs向webapi发出http.get请求,我得到TypeError:undefined不是Object.ga中的函数[作为副本]。我是angularjs和webapi的新手。我还注意到,当我将data.id传递给警报时,它返回undefined。我尝试过在网上搜索的所有解决方案。
angular.module('schoolManager').controller('UsersController', ["$rootScope", "$scope", "$filter", "dataService", function ($rootScope, $scope, $filter, dataService) {
$scope.items = [];
$scope.roles = [];
$scope.editItem = {};
$scope.isNewItem = false;
$scope.focusInput = false;
var baseAddress = 'http://localhost:49535/api/account';
$scope.loadEditForm = function (id) {
//$scope.loadRoles(id);
if (!id) {
$scope.editItem = {};
$scope.isNewItem = true;
$("#modal-user-edit").modal();
$scope.focusInput = true;
return false;
}
else {
$scope.isNewItem = false;
}
$scope.loading = true;
dataService.getItems(baseAddress + '/' + id)
.success(function (data) {
alert(data.UserId);
angular.copy(data, $scope.editItem);
$("#modal-user-edit").modal();
$scope.focusInput = true;
$scope.loading = false;
})
.error(function () {
toastr.error($rootScope.lbl.errorLoadingUser);
$scope.loading = false;
});
}
$scope.load();
}]);
答案 0 :(得分:0)
很难说明所提供的内容,但错误表示" cb- {item.Username}"也许那应该是cb - {{item.Username}}