简体   繁体   中英

AngularJS ng-repeat not showing values

I have a simple ng-repeat block that looks like this:

<div ng-repeat = "Service in getServices()">
    {{Service}}
</div>

The corresponding controller defines getServices()

$scope.getServices = function(){
    try{
        var services = [];
        for (var i = 0; i < $rootScope.Store.Services.length; i++){
            services.push($rootScope.Store.Services[i].ServiceID);
        }
        console.log('services: ' + JSON.stringify(services))
        return services;

    }
    catch (err){
        console.log('no services')
        return [];
    }
};

For some reason, however, I am getting no Services in my view. I know I can just repeat directly over the $rootScope and that's how I had it before but this was an effort to debug. I am getting Services in my console:

services: ["ATM","DELI","DIESEL"]

Also, when I change the getServices() function to something like this:

$scope.getservices = function(){
  var test = ["a", "b", "c"];
  return test;
}

It does update the view correctly. Not sure what's going on! Note that I have many other perfectly working ng-repeats in the app.

Solved

I have no idea why but after removing iscroll from this particular page, it works fine -_-

Since you mention that iScroll was the problem, have you checked there aren't any global variable collisions?

Maybe you should implement iScroll via Angular: http://ngmodules.org/modules/ng-iScroll

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM