2016-12-15 9 views
0

WrapLayoutに子を追加できません。ここに私のchoose_time.htmlは次のとおりです。ここでNativescript。 Angular2 + Typescript。子をWrapLayoutに追加する

<WrapLayout #wrapLayout> 
</WrapLayout> 

は私choose_time.component.tsです:私は間違っ

import { Component, ElementRef, ViewChild } from "@angular/core"; 
import { WrapLayout } from 'ui/layouts/wrap-layout' 
import labelModule = require("ui/label"); 

@Component({ 
    selector: "choose_time", 
    providers: [], 
    templateUrl: "pages/choose_time/choose_time.html", 
    styleUrls: ["pages/choose_time/choose_time-common.css"] 
}) 

export class ChooseTimeComponent implements OnInit { 
@ViewChild("wrapLayout") wrapLayout: ElementRef; 

    constructor(
    private page: Page) {} 

    ngOnInit() { 
     this.page.actionBarHidden = true; 
     this.setChildren() 
    } 

    setChildren(){ 
     var label = new labelModule.Label(); 
     label.text = "text"; 
     this.wrapLayout.addChild(label) 
    } 

何をしているのですか?

答えて

2

TypeScript対応のエディタを使用してTSサポートが正しく設定されていると、コードの最後の行にエラーが表示されます。

(<WrapLayout>this.wrapLayout.nativeElement).addChild(label);に変更すると、上司のように機能します!ここの鍵は.nativeElementを追加することです。

+0

はい、動作します。どうもありがとう!!! –

+0

クールで、他の人が簡単に見つけられるように答えを受け入れてください。乾杯! –

関連する問題