【发布时间】:2016-09-30 14:05:52
【问题描述】:
我正在按照本指南创建一个 nativescript 自定义组件 http://moduscreate.com/custom-components-in-nativescript/,但它对我不起作用
我有一个文件夹 pages,里面有一个名为 main 的文件夹。 main 有几个文件
main.html
<StackLayout
xmlns="http://schemas.nativescript.org/tns.xsd"
xmlns:hello="pages/helllo"
loaded="pageLoaded" >
<hello:hello/>
</StackLayout>
main.component.ts
import { Component, ElementRef, OnInit, ViewChild} from "@angular/core";
import { Page } from "ui/page";
import colorModule = require("color");
var Color = colorModule.Color;
@Component({
selector: "my-app",
templateUrl: "pages/main/main.html",
styleUrls: ["pages/main/main-common.css"]
})
export class MainComponent implements OnInit{
constructor(private page: Page) {
}
ngOnInit() {
this.page.actionBarHidden = true;
}
}
我也有 main-common.css 但这并不重要。然后我在 pages 中有另一个名为 hello 的文件夹,其中只有一个文件
hello.html
<StackLayout width="100%" height="100%" backgroundColorr="red">
<Label class ="h1" text="h1 hello world" color="black"></Label>
<Label class ="h1" text="h1 hello world" color="black"></Label>
<Label class ="h1" text="h1 hello world" color="black"></Label>
<Label class ="h1" text="h1 hello world" color="black"></Label>
<Label class ="h1" text="h1 hello world" color="black"></Label>
<Label class ="h1" text="h1 hello world" color="black"></Label>
<Label class ="h1" text="h1 hello world" color="black"></Label>
<Label class ="h1" text="h1 hello world" color="black"></Label>
<Label class ="h1" text="h1 hello world" color="black"></Label>
<Label class ="h1" text="h1 hello world" color="black"></Label>
<Label class ="h1" text="h1 hello world" color="black"></Label>
</StackLayout>
但是,无论我做什么,hello 组件都没有显示,我只是得到一个空屏幕。我还尝试将 hello.html 文件中的这一行 xmlns:hello="pages/helllo" 更改为 xmlns:hello="../helllo",但我什至没有得到任何错误消息。有人能指出我做错了什么吗?
【问题讨论】:
-
自定义组件仅在原版 NS 中起作用,您需要将它作为 Angular 共享的东西,不确定它叫什么,因为我不使用 Angular
-
使用 vanilla NS 和 angular 哪个更好?
-
每个都有优点和缺点,我使用香草,因为我有同样的问题和更多的事情,当我开始使用 NS 时会导致错误,但如果你熟悉 ng2 或需要重用它,它会更好网站逻辑
标签: android angular typescript nativescript