【问题标题】:Nativescript. Angular2 + Typescript. Add Child to WrapLayout本机脚本。 Angular2 + 打字稿。将子级添加到 WrapLayout
【发布时间】:2017-05-01 04:17:02
【问题描述】:

我无法将孩子添加到 WrapLayout。这是我的choose_time.html:

<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)
    }

我做错了什么?

【问题讨论】:

    标签: angular typescript nativescript addchild


    【解决方案1】:

    使用 TypeScript 感知编辑器并且正确配置 TS 支持时,您会在代码的最后一行看到错误。

    将其更改为(&lt;WrapLayout&gt;this.wrapLayout.nativeElement).addChild(label);,它就像老板一样工作!这里的关键是添加.nativeElement

    【讨论】:

      猜你喜欢
      • 2012-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-11
      • 2015-09-23
      • 1970-01-01
      • 2022-12-05
      • 2020-09-30
      相关资源
      最近更新 更多