我如何应用控制器对象上的每个循环

时间:2015-09-01 10:03:28

标签: angularjs angularjs-scope angularjs-ng-repeat angularjs-service

我在使用Angular foreach循环时遇到问题,当我尝试访问时我得到未定义的值请建议我如何使用下面的代码以便我可以访问该值并将其存储到$ rootScope

patientsService.getChartData({  filter:$scope.patientid }).success(function (result) {
                    $scope.chartdata = result.items;
                    alert("success");
                    angular.forEach(result.items, function (item) {

                        alert(item.Image);
                        if (item.TeethNO == 1) { $rootScope.tooth1 = item.Image; }
                        if (item.TeethNO == 2) { $rootScope.tooth2 = item.Image; }
                        if (item.TeethNO == 3) { $rootScope.tooth3 = item.Image; }
                        if (item.TeethNO == 17) { $rootScope.tooth17 = item.Image; }
                    });
                });
            }

值的实体是:

public  int PatientID { get; set; }
            public  int TeethNO { get; set; }          
            public  string Image { get; set; }           
            public  string Description { get; set; }

1 个答案:

答案 0 :(得分:0)

我通过console.log得到了我的答案(result.items);实际上在结果中我得到了视图第一个字母自动变为然后我改变了警告(item.Image);提醒(item.image); 谢谢大家的支持