【发布时间】:2017-03-27 15:35:34
【问题描述】:
我创建了一个新的测试应用
> ng new TestApp
然后我安装 nativescript-ngx-magic
> npm i @wwwalkerrun/nativescript-ngx-magic --save
然后新建一个app.component.tns.html
<ActionBar title="Magic!" icon="" class="action-bar">
</ActionBar>
<StackLayout class="p-20">
<Label text="NativeScript is Neat." class="h1 text-center"></Label>
</StackLayout>
创建一个空白的 app.component.tns.css
然后更改我的 app.component.ts 以便它可以与 nativescript-ngx-magic 一起使用:
import { Component } from '@wwwalkerrun/nativescript-ngx-magic';
@Component({
moduleId: module.id,
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.css']
})
export class AppComponent {
title = 'app works!';
}
现在运行应用程序
> npm run start.android
该应用程序有效
然后我创建一个自定义控件:
> ng g component custom
然后再次创建一个空白的 custom.component.tns.css 创建一个新的 custom.component.tns.html
<Label text="My Custom Component" class="h1 text-center"></Label>
更改 custom.component.ts 代码:
import { Component } from '@wwwalkerrun/nativescript-ngx-magic';
@Component({
moduleId: module.id,
selector: 'app-custom',
templateUrl: 'custom.component.html',
styleUrls: ['custom.component.css']
})
export class CustomComponent {
}
并将这个自定义标签添加到我的 app.component.tns.html 中,现在它看起来像这样:
<ActionBar title="Magic!" icon="" class="action-bar">
</ActionBar>
<StackLayout class="p-20">
<Label text="NativeScript is Neat." class="h1 text-center"></Label>
<app-custom></app-custom>
</StackLayout>
然后当我再次运行应用程序时:
> npm run start.android
我希望看到我的自定义组件,但应用看起来还是一样。
我错过了什么?
如果我将自定义组件添加到 .html 文件而不是 tns.html 并使用 ng serve 运行,那么网站会正确显示自定义组件。只是不是应用程序。
在使用 nativescript-ngx-magic 时这是否可能?
【问题讨论】:
标签: nativescript angular2-nativescript