如何使用angular2和Typescript隐藏android actionbar?

oli*_*ier 3 android typescript nativescript

我有一个简单的html文件:

<StackLayout orientation="vertical" actionBarHidden="true">
      <Image src="res://buy" stretch="none" horizontalAlignment="center"></Image>
</StackLayout>
Run Code Online (Sandbox Code Playgroud)

但是当我使用时:

<Page actionBarHidden="true">
  <StackLayout orientation="vertical">
      <Image src="res://buy" stretch="none" horizontalAlignment="center"></Image>
  </StackLayout>
</Page>
Run Code Online (Sandbox Code Playgroud)

它会中断页面​​。.操作栏未隐藏,并且内容和操作栏之间有巨大的空白。

我为我的应用程序使用angular2和打字稿。

我怎么了

任何帮助,不胜感激!

Geo*_*rds 6

您可以在组件 JS 中定位页面属性,如下所示:

export class HomePage implements OnInit {
    page: Page;
    ngOnInit() {
        this.page = <Page>topmost().currentPage;
        this.page.actionBarHidden = true;
    }
}
Run Code Online (Sandbox Code Playgroud)

您还需要导入import {topmost} from "ui/frame";import {Page} from "ui/page";

这样你就不需要标签(在 Angular 2 组件中是隐含的)。

我希望这有帮助!

此外,只是为了跟进 Brad 关于自闭标签的评论 - 您会发现使用 Angular,显式结束标签(正如您所做的那样)工作得更好。


Hri*_*mov 5

有一个更简单的解决方案。在Angular 4.1.0和NativeScript 上测试3.0.0

import { Page } from "ui/page";

export class AppComponent {
    constructor(private page: Page) {
        page.actionBarHidden = true;
    }
}
Run Code Online (Sandbox Code Playgroud)

您可以ActionBar从组件的构造函数控制的可见性。

StackOverflow答案:https ://stackoverflow.com/a/39962992/2765346