¿Existe ngRepeat en Angular 2?
He leído varias entradas de seguimiento de problemas en relación con Angular 2 y su implementación de ng-repeat, pero tal como está, en realidad no he averiguado si realmente existe todavía.
¿Es posible usar ng-repeat
en angular 2?
27
3 answers
Angular 2.0 Release
Mi-componente.ts:
import { Component } from 'angular2/core';
@Component({
selector: 'my-component',
templateUrl: './my-component.html'
})
export class MyComponent{
public values: number[] = [1, 2, 3];
}
Mi-componente.html:
<div *ngFor='let value of values; trackBy: index;'>
{{ value }}
</div>
44
Author: rckd,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-08-25 21:55:12
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-08-25 21:55:12
De alfa 28 a 30 es la siguiente sintaxis:
import { NgFor } from 'angular2/angular2';
@View({ directives: [NgFor] })
<div *ng-for="#item of items">
3
Author: Ajden Towfeek,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-07-13 19:12:16
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-07-13 19:12:16
ACTUALIZACIÓN: este comentario está desactualizado, consulte la respuesta aceptada
OK, ACTUALMENTE, lo siguiente funciona.
/// <reference path="typings/angular2/angular2.d.ts" />
import {Component, View, For, bootstrap} from 'angular2/angular2';
// Annotation section
@Component({
selector: 'itemlist'
})
@View({
directives: [For]
template: `<h2 (click)="onClick()">Hello {{ name }}</h2><ul><li *for="#item of items">{{item.name}}</li></ul>`
})
// Component controller
class ItemList {
name: string;
items: array;
constructor() {
this.name = 'Sub';
this.items = [];
this.addItem("Dog 0");
this.addItem("Dog 1");
this.addItem("Dog 2");
}
addItem(name){
this.items.push({id: this.items.length, name: name});
}
onClick() {
console.log(this.items);
this.addItem("Dog "+this.items.length);
}
}
Lo que me faltaba
Necesitas importar For
(línea 3)
Debe declarar su dependencia de For
para el componente en cuestión (línea 9)
La sintaxis correcta para" ng-repeat " es ACTUALMENTE *for="#item of items"
Parece haber cambiado bastante ya durante el desarrollo, por lo que no me sorprendería si cambia de nuevo.
3
Author: CT14.IT,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-12-16 14:01:02
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-12-16 14:01:02