我正在嘗試處理NativeScript應用程序中的硬件返回按鈕。我在Angular上使用NativeScript 2.3.0版本。NativeScript處理返回按鈕事件
這是我在main.ts
文件
// this import should be first in order to load some required settings (like globals and reflect-metadata)
import { platformNativeScriptDynamic, NativeScriptModule } from "nativescript-angular/platform";
import { NgModule,Component,enableProdMode } from "@angular/core";
import { AppComponent } from "./app.component";
import { NativeScriptRouterModule } from "nativescript-angular/router";
import { routes, navigatableComponents } from "./app.routing";
import { secondComponent } from "./second.component";
import {AndroidApplication} from "application";
@Component({
selector: 'page-navigation-test',
template: `<page-router-outlet></page-router-outlet>`
})
export class PageNavigationApp {
}
@NgModule({
declarations: [AppComponent,PageNavigationApp,secondComponent
// ...navigatableComponents
],
bootstrap: [PageNavigationApp],
providers:[AndroidApplication],
imports: [NativeScriptModule,
NativeScriptRouterModule,
NativeScriptRouterModule.forRoot(routes)
],
})
class AppComponentModule {
constructor(private androidapplication:AndroidApplication){
this.androidapplication.on("activityBackPressed",()=>{
console.log("back pressed");
})
}
}
enableProdMode();
platformNativeScriptDynamic().bootstrapModule(AppComponentModule);
我與
import {AndroidApplication} from "application";
在appComponentModule
我註冊事件activityBackPressed
的constrouctor導入應用程序之後,只是做了的console.log。
這不起作用。
我在這裏錯過了什麼?
謝謝艾迪,但我怎樣才能以編程方式退出應用程序..我想要後退按鈕退出應用程序時,在其他主視圖上,你在下面的答案中提到,這不是最佳做法。 http://stackoverflow.com/questions/41307447/nativescript-with-angular-2-on-android-how-to-close-my-app – krv
我想如果你的導航棧是'空'後退按鈕應該退出應用程序。 –
現在使用這些工具集https://github.com/NathanaelA/nativescript-master-technology – krv