私は基本的にコンポーネントを入れ子にしようとしています。私が持っているコードで説明するのが簡単になると思います。データバインディングを持つコンポーネントでディレクティブを使用するにはどうすればよいですか?
基本的に私は2つのコンポーネントを持っています、私は特定の方法でもう一方のコンポーネントを使用したいです。ここで私は、彼らが設定した方法は次のとおりです。
test.component.ts
:
import { Component } from '@angular/core';
@Component({
selector: 'test',
templateUrl: 'partials/test.html'
})
export class TestComponent {
constructor() {}
}
another.component.ts
:
import { Component } from '@angular/core';
import { TestComponent } from './test.component';
interface Circle {
show: boolean,
data: any
}
@Component({
selector: 'another',
directives: [ TestComponent ],
templateUrl: '/partials/another.html'
})
export class AnotherComponent {
circles: Circle[] = [];
constructor() {
let testElement = document.createElement('test'),
defaultCircles = [
{ show: true, data: testElement }
];
this.circles = defaultCircles;
}
}
partials/another.html
は:
<ul>
<li *ngFor="let circle of circles; let i = index">
{{circle.data}} <!-- this just shows [object HTMLElement] -->
</li>
</ul>
ディレクティブの内容を表示するにはどうすればよいですか?私はdata: testElement
をdata: '<test></test>'
に置き換えようとしましたが、それでも動作しません、それはちょうどテキスト<test></test>
を示しています。
「circle.data」の内容は何ですか? –
'data:testElement'とtestElement私は' document.createElement( 'test') 'と' ' –
Jared