我試圖阻止回去在我的本機應用程序使用NativeScript與angular2,我試圖按照文件:: https://docs.nativescript.org/core-concepts/navigation#example-8--prevent-user-from-going-back-using-clearhistory-property,一旦我跑我的應用程序,我得到一個錯誤:Nativescript角2導航最上面
JS: Angular 2 is running in the development mode. Call enableProdMode() to enabl
e the production mode.
JS: ANGULAR BOOTSTRAP DONE.
JS: EXCEPTION: Error: Failed to load Page from entry.moduleName: ListPage in [nu
ll]
JS: ORIGINAL EXCEPTION: Error: Failed to load Page from entry.moduleName: ListPa
ge
這是我的源代碼:
import {Component, ElementRef, OnInit, ViewChild} from "angular2/core";
import {TextField} from "ui/text-field";
import {Frame} from "ui/frame";
import {Grocery} from "../../shared/grocery/grocery";
import {GroceryListService} from "../../shared/grocery/grocery-list.service";
import frameModule = require("ui/frame");
var socialShare = require("nativescript-social-share");
@Component({
selector: "list",
templateUrl: "pages/list/list.html",
styleUrls: ["pages/list/list-common.css", "pages/list/list.css"],
providers: [GroceryListService]
})
export class ListPage implements OnInit {
groceryList: Array<Grocery> = [];
grocery: string = "";
isLoading = false;
listLoaded = false;
topmost = frameModule.topmost();
@ViewChild("groceryTextField") groceryTextField: ElementRef;
constructor(private _groceryListService: GroceryListService) { }
share() {
let list = [];
for (let i = 0, size = this.groceryList.length; i < size; i++) {
list.push(this.groceryList[i].name);
}
let listString = list.join(", ").trim();
socialShare.shareText(listString);
}
delete(grocery: Grocery) {
this._groceryListService.delete(grocery.id)
.subscribe(() => {
var index = this.groceryList.indexOf(grocery);
this.groceryList.splice(index, 1);
})
}
add() {
if (this.grocery.trim() === "") {
alert("Enter a grocery item");
return;
}
// Dismiss the keyboard
let textField = <TextField>this.groceryTextField.nativeElement;
textField.dismissSoftInput();
this._groceryListService.add(this.grocery)
.subscribe(
groceryObject => {
this.groceryList.unshift(groceryObject);
this.grocery = "";
},
() => {
alert({
message: "An error occurred while adding an item to your list.",
okButtonText: "OK"
});
this.grocery = "";
}
)
}
ngOnInit() {
this.isLoading = true;
this._groceryListService.load()
.subscribe(loadedGroceries => {
loadedGroceries.forEach((groceryObject) => {
this.groceryList.unshift(groceryObject);
});
this.isLoading = false;
this.listLoaded = true;
});
this.topmost.navigate({
moduleName: "ListPage",
clearHistory: true
});
}
}
我一直在谷歌上搜索,並不能得到我想要的東西。在這種情況下,我使用的教程NativeScript具有角JS 2 :) 謝謝
的部分解決方案,您好我使用該代碼爲防止回去,當應用程序enetring這個模塊..它正確? –