I created a new blank project for testing purposes, with a custom component. It works fine if i use the component in the html of the homepage. But what i want to do, is use the component in a list. This is where i am stuck. Adding items (strings for instance) in the list data is working fine and showing up. But how do i get the rendered html of the component in that list? Need a push in the right direction.
home.html
<ion-header>
<ion-navbar>
<ion-title>
Ionic Blank
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<button ion-button color="light" (tap)="tapEvent($event)">Light</button>
<ion-item *ngFor="let item of items">
{{item}}
</ion-item>
<test-one></test-one>
</ion-content>
home.ts
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
items: string[] = [];
constructor(public navCtrl: NavController) {
}
tapEvent(event)
{
console.log(event);
this.items.push("bier!");
}
}
test-one.html
<!-- Generated template for the TestOneComponent component -->
<div (tap)="tapEvent($event)">
{{text}}
</div>
test-one.ts
import { Component, ElementRef, Renderer } from '@angular/core';
/**
* Generated class for the TestOneComponent component.
*
* See https://angular.io/api/core/Component for more info on Angular
* Components.
*/
@Component({
selector: 'test-one',
templateUrl: 'test-one.html'
})
export class TestOneComponent {
text: string;
constructor(private element : ElementRef, private renderer : Renderer) {
console.log('Hello TestOneComponent Component');
this.text = 'TestOneComponent';
}
tapEvent(event)
{
console.log("TestOneComponent tapEvent");
}
// Manipulation test
ngAfterViewInit()
{
console.log(this.element);
this.renderer.setElementStyle(this.element.nativeElement, 'color', '#f00');
}
}