2

I'm trying to set-up a simple ng-for to loop over a list of project in angular but got stuck with it. I already tried the solution in Angular2 exception: Can't bind to 'ngFor' since it isn't a known native property (fix missing #) but without success.

EXCEPTION: Template parse errors:
Can't bind to 'ng-forOf' since it isn't a known native property ("<div class="ui link cards">
    <div class="card" [ERROR ->]*ng-for="#project of projects">
        <div class="image">
            <img src="{{project.illustrat"): Projects@1:22
Property binding ng-forOf not used by any directive on an embedded template ("<div class="ui link cards">
    [ERROR ->]<div class="card" *ng-for="#project of projects">
        <div class="image">
            <img src="{"): Projects@1:4

index.js

import * as stylesheet from '../assets/styles/app.scss';

import $ from 'jquery';
import jQuery from 'jquery';
// export for others scripts to use
window.$ = $;
window.jQuery = jQuery;


import 'zone.js/lib/browser/zone-microtask';
import 'reflect-metadata';
import 'babel-polyfill';

import {provide} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';

import {App} from './app.component.js'
bootstrap(App, []);

app.component.js

import {Component} from 'angular2/core';
import {Projects} from '../app/projects/projects';

@Component({
    selector: 'my-app',
    template: '<projects>Loading...</projects>',
    directives: [Projects]
})

export class App {
    constructor(projects:Projects) {
        this.projects = projects;
        console.log(this.projects);
    }
}

index.html

<html>
<body>
    <my-app>
          <ng-content></ng-content>
    </my-app>
<script src="dist/app.js"></script>
</body>
</html>

project.js

import {Component, View} from 'angular2/core';
import {NgFor} from 'angular2/common';

@Component({
    selector: 'projects, [projects]'
})
@View({
    //templateUrl: '/app/projects/projects.html',
    directives: [NgFor],
    template: "<div *ng-for='#project of projects'> <p>{{project.description}} </div>",
})
export class Projects {
    constructor() {
        this.projects = [
            {
                "customer": "Matt Giampietro",
                "description": "Lorem ipsum dolor sit amet…",
                "name": "project #1"
            },
            {
                "customer": "test",
                "description": "Lorem ipsum dolor sit amet…",
                "name": "project #2"
            }
        ]
    }
}

Question

  • How do I solve this?
  • fail both with internal/external template (i.e. templateUrl)
Community
  • 1
  • 1
Édouard Lopez
  • 40,270
  • 28
  • 126
  • 178

1 Answers1

4

ng-for isn't correct in recent Angular versions. Templates were changed to case-sensitive. Now this should be ngFor

See also Can't bind to 'ng-forOf' since it isn't a known native property

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567