Search code examples
javascriptangularjsangularjs-scopeangularjs-ng-repeat

anuglar js: ng-repeat doesn't displaying anything


I'm not really a js guy but i tried to show something with the ng-repeat in angular. But it doesn't display anything.

HTML:

<div class="list-block" ng-controller="ContactController as acontact">
<ul>
   <li class="item-content" ng-repeat="customer in acontact.customers"product>
       <div class="item-media"><i class="icon icon-f7"></i></div>
       <div class="item-inner">
           <div class="item-title">contact: {{ customer[0].Name }}</div>
           <div class="item-after">Label</div>
       </div>
   </li>
</ul>
</div>

JS

var app = angular.module('contact', []);

app.controller('ContactController', function($scope){
    var customers = myContext.customer.toArray();

    $.when(customers).then(function(customers) {
        $scope.customers = customers;
    }); 
});

Debug I tried to find error out with the debug chrome extension: DebugAngular Scope Image Customer in Console.log()

This Image i can see for 1 sec and then it goes away and only the title stays there. 1 sec

Maybe somebody know what i'm doing wrong? Best Regards


Solution

  • I agree with the above answers, as far as customer is an object and not an array. But maybe try accessing the name with:

    customer.initData.Name  
    

    i.e.

    <li class="item-content" ng-repeat="customer in customers"product>
        <div class="item-media"><i class="icon icon-f7"></i></div>
        <div class="item-inner">
            <div class="item-title">contact: {{ customer.initData.Name }}</div>
            <div class="item-after">Label</div>
         </div>
    </li>
    

    and because you attached customers to $scope, here:

     $.when(customers).then(function(customers) {
            $scope.customers = customers;
        }); 
    

    It means you dont have to reference the controller object, ng-repeat="customer in acontact.customers" Try just using

    ng-repeat="customer in customers"