あなたは、あなたのプロジェクトを作成するためにNativeScript Anguler2テンプレートを使用している場合は、カスタムコンポーネント読み込むことができますbuilder.loade
を使用せずにTabViewで。このようなカスタムコンポーネントを作成する方法と、それをTabView
に追加する方法については、以下の添付の例を参照してください。
product.component.ts
import {Component, Input} from "@angular/core";
@Component({
selector: 'product-component',
template: `
<StackLayout>
<Label [text]="data" class="name"></Label>
</StackLayout>
`
})
export class ProductComponent {
@Input() data: string;
}
app.component.html
<GridLayout>
<TabView #tabView>
<StackLayout *tabItem="{title: 'Tab1'}">
<product-component data="Sample title" ></product-component>
</StackLayout>
<StackLayout *tabItem="{title: 'Tab2'}">
<Label text="This is Label in Tab 2"></Label>
</StackLayout>
</TabView>
</GridLayout>
main.ts
import { platformNativeScriptDynamic, NativeScriptModule } from "nativescript-angular/platform";
import { NgModule } from "@angular/core";
import { AppComponent } from "./app.component";
import {ProductComponent} from "./product.component"
@NgModule({
declarations: [AppComponent, ProductComponent],
bootstrap: [AppComponent],
imports: [NativeScriptModule],
})
class AppComponentModule {}
platformNativeScriptDynamic().bootstrapModule(AppComponentModule);
重要な部分は、宣言でカスタムコンポーネントを追加することですmain.ts
ファイルにあります。異なるコンポーネント間でデータを共有するには、プロジェクトで@Input()
を使用します。あなたはそれについてもっと読むことができますhere
yeahhh私は 'myPage'を得るには、実際に私は 'product_lists.html'ページを読み込もうとしているTabviewをdynamic.howを読み込もうとしています。 –
私が間違っているかどうか教えてください。私はあなたが1ページに入っていることを理解しており、そのページ内でTabViewを動的に生成しています。次に、別のページ( 'product_lists'ページ)をTabView項目にロードします。もう少し 'XML'とjsファイルを投稿して、より良く見えるようにできましたか? –
ええ..あなたは正しいです。このtabview内にproductList.htmlページが必要です。私のtablistComponet.tsファイルは次のとおりです。for(var index = 0; index