0

So, i'm trying to iterate on an array of objects called 'cards', to display some info inside of them using ng-for, but it seems the data isn't being bound to the html, as the page stays empty even though the arrays and objects are populated. Any ideas why? Thanks in advance <3

newsController.js

'use strict';

angular
    .module('e-commerce')
    .controller('newsController', newsController)
    .directive('newsDirective', newsDirective);

/** @ngInject */
function newsController($scope) {
    var vm = this;
    $scope.cards = 
    [
        {
        dscTitulo : 'Lorem Ipsum',
        dscSubtitulo: 'Dolor sit amet conecticur adsplicit',
        dscNomeBotao: 'Ennunciatis Alan',
        urlFoto: 'https://i.pinimg.com/originals/38/bf/39/38bf39dd4bd45e83128c9600f30cba29.jpg'
        }
    ];
}

news.html

<div>
    <div *ngFor="let card of cards;">
        <li>
            {{card.dscTitulo}}
            {{card.dscSubTitulo}}
        </li>
    </div>
</div>
2
  • 1
    The javascript you provided is AngularJS (v1) and the template you provided is Angular 2+. What angular version are you trying to use? Commented Oct 19, 2020 at 23:57
  • The project i'm working is in AngularJs 1, should i change something in the template? Commented Oct 20, 2020 at 8:36

1 Answer 1

1

The problem is you're mixing Angular 2+ (your template) with AngularJS V1 (your javascript). Your template is currently using *ngFor which is an Angular 2+ directive. You need to change your template to use ng-repeat.

<div>
  <div ng-repeat="card in cards">
    <li>
      {{card.dscTitulo}}
      {{card.dscSubTitulo}}
    </li>
  </div>
</div>

https://docs.angularjs.org/api/ng/directive/ngRepeat

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.