Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.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
Html 使用ng repeat不会显示列表对象_Html_Angularjs - Fatal编程技术网

Html 使用ng repeat不会显示列表对象

Html 使用ng repeat不会显示列表对象,html,angularjs,Html,Angularjs,我不确定我做错了什么,但我的对象不希望在我的局部视图中显示angular的ng repeat 剧本 不确定这是否有用,但我在ng init上调用了我的方法 <div ng-controller="ExecutivePayController" ng-init="LoadExecutivesPay()"> 首先,您要检查data.issucess{和您的输出是否没有它 其次,您使用的是data.Results.length;。这里也没有结果。首先,由于您不使用angular的方式进行

我不确定我做错了什么,但我的对象不希望在我的局部视图中显示angular的ng repeat

剧本

不确定这是否有用,但我在ng init上调用了我的方法

<div ng-controller="ExecutivePayController" ng-init="LoadExecutivesPay()">

首先,您要检查data.issucess{和您的输出是否没有它


其次,您使用的是data.Results.length;。这里也没有结果。

首先,由于您不使用angular的方式进行AJAX调用,您需要调用angular.fromJsondata.Results。此外,由于这是一个异步操作,您必须手动触发摘要循环。因此,您必须调用$scope。$apply更新您的$scope.ExecutivePayList

最终代码:

$scope.ExecutivePayList = [];
$scope.LoadExecutivesPay = function () {
    $.get(loadExecutivesPayUrl, function (data) {
        if (data.IsSuccess) {
            //Load data
            $scope.ExecutivePayList.length = 0;
            $scope.ExecutivePayList = angular.fromJson(data.Results);
            for (var i = 0; i < data.Results.length; i++) {
                $scope.ExecutivePayList.push(data.Results[i])
            }
            console.log($scope.ExecutivePayList);
            $scope.$apply(); // Here you trigger the digest cycle.
        }
    });
};

你为什么不使用$http.get?我现在就实现了。习惯性地使用$http.get仍然不能解决我的问题。你能在这里显示输出吗?你能显示你的输出吗JSON@VinodKumarKashyap请参阅edittry making if data.issucces{此选项至if data.issucces==true{该部分工作正常。当我调用$scope.ExecutivePayList=angular.fromJsondata.Results时,它显示$scope.ExecutivePayList有数据,但当我重复时,它不会显示数据。非常感谢!!
{SectionID: "00000000-0000-0000-0000-000000000000", Results: Array(2), Message: null, IsSuccess: true, DetailedMessage: null}
Results: Array(2)
0:{SectionID: "b8e6466e-44b8-4a47-bdc6-a84e07200780", NameOfIncumbent: "Daily M", Position: "CEO", PatersonGrade: "", NumMonthsInPosition: 12}
1:{SectionID: "2290a579-7f86-437f-a806-36049eeb7c8b", NameOfIncumbent: "Field RH", Position: "CEO", PatersonGrade: "", NumMonthsInPosition: 12}
<div ng-controller="ExecutivePayController" ng-init="LoadExecutivesPay()">
$scope.ExecutivePayList = [];
$scope.LoadExecutivesPay = function () {
    $.get(loadExecutivesPayUrl, function (data) {
        if (data.IsSuccess) {
            //Load data
            $scope.ExecutivePayList.length = 0;
            $scope.ExecutivePayList = angular.fromJson(data.Results);
            for (var i = 0; i < data.Results.length; i++) {
                $scope.ExecutivePayList.push(data.Results[i])
            }
            console.log($scope.ExecutivePayList);
            $scope.$apply(); // Here you trigger the digest cycle.
        }
    });
};
$scope.LoadExectivesPayUrl = function() {
   $http.get(loadExecutivesPayUrl).then((data) => {
      if(data.IsSuccess) {
            //Load data
            $scope.ExecutivePayList.length = 0;

            //No need to parse json because angular has done this automatically 
            //for you

            for (var i = 0; i < data.Results.length; i++) {
                $scope.ExecutivePayList.push(data.Results[i])
            }
            console.log($scope.ExecutivePayList);
            // No need to $scope.$apply() , since digest cycle is performed 
            // within $http operation
      }
   })
}