1
我目前正在編寫一個TypeScript應用程序,其中按鈕以編程方式創建並添加到GridLayout。NativeScript按鈕點擊事件不會在導航後調用ngOnInit,但onTap會做
let currentPage;
let topFrame = frameModule.topmost();
currentPage = topFrame.currentPage;
currentPage.actionBarHidden = true;
currentPage.backgroundImage = currentPage.ios ? "res://baby_large_file.jpg" : "res://baby_large_file";
var onTap = function (eventData) {
this.login();
};
var grid = new GridLayout();
let feeding = new buttonModule.Button();
feeding.text = "F";
feeding.id = "feeding";
feeding.on(buttonModule.Button.tapEvent, onTap, this);
grid.addChild(feeding);
grid.addRow(new ItemSpec(1, GridUnitType.star));
grid.addColumn(new ItemSpec(1, GridUnitType.star));
GridLayout.setRow(feeding, 0);// shareButton set to row 2
GridLayout.setColumn(feeding, 0);// shareButton set to row 2
currentPage.content = grid;
登錄功能簡單地調用用戶的服務,如果應用程序有它們被路由到一個新的頁面有效令牌:
login() {
this.userService.login(this.user)
.subscribe(
() => this.router.navigate(["/locations"]),
(error) => alert("Unfortunately we could not find your account.")
);
}
的ngOnInit功能永遠不會在這個新的一頁名爲
export class Locations implements OnInit {
constructor (private router: Router, private locationService: LocationService) {}
ngOnInit() {
console.log('ngOnInit');
}
}
與爲什麼這不起作用任何幫助將是非常讚賞