My goal is to create a component that can take a custom element and iterate over it using provided data.
Here is what i have been able to come up with, and it works fine. But i'm not satisfied. I want something that does not require wrapping the custom element in a <template>
tag.
import {Component, Input, Output, EventEmitter} from 'angular2/core';
@Component({
selector: 'sub',
template: `
<ng-content></ng-content>
`
})
export class SubComponent {}
@Component({
selector: 'my-app',
template: `
<sub>
<template ngFor #listItem [ngForOf]="list" #i="index"> //<--don't want this tag
<div>{{listItem | json}}</div>
<p>{{i}}</p>
</template>
</sub>
`,
directives: [ SubComponent ]
})
export class AppComponent {
list = [{name: 'John', age: 26},{name: 'Kevin', age: 26}, {name:'Simmons', age:26}];
}
- the code above is an edit of this plunker.
- seen the suggestion here but were quite vague.