单击图像移动另一个页面不起作用
Onclick image to move another page is not working
我是 nativescript 的新手。我正在从警报页面导航到
导航页面。我已经发布了所有相关的codes.please检查它。
我没有得到任何 issue.When 执行图像 onClick 我可以调用此方法 onNotification()
。
我可以看到这个控制台登录命令提示符
console.log("SteveCheck", "Test");
但是我不知道,为什么它没有移动到通知页面
单击警报中的按钮 page.Below 我已添加所有相关代码。
app.module.ts:
import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
import { AlertComponent } from "./AlertFolder/alert.component";
import { NativeScriptRouterModule } from "nativescript-angular/router"
import {AppRoutes, AppComponents } from "./app.routing";
@NgModule({
declarations: [AlertComponent, ...AppComponents],
bootstrap: [AlertComponent],
imports: [
NativeScriptModule,
NativeScriptRouterModule,
NativeScriptRouterModule.forRoot(AppRoutes)
],
schemas: [NO_ERRORS_SCHEMA],
})
export class AppModule {}
app.routing.ts:
import { AlertComponent } from "./AlertFolder/alert.component";
import { NotificationComponent } from "./Noficiation/notification";
export const AppRoutes:any = [
{ path: "", component: AlertComponent },
{ path: "NotificationPage", component: NotificationComponent}
];
export const AppComponents: any = [
AlertComponent,
NotificationComponent
];
alert.component.ts:
@Component({
selector: "sdk-child-component",
moduleId: module.id,
....
})
export class AlertComponent {
.....
.....
public constructor(private router: Router, private routerExtensions: RouterExtensions){
this.alertList = [];
}
onNotification() {
console.log("SteveCheck", "Test");
this.router.navigate(["NotificationPage"]);
}
}
alert.component.html:
<StackLayout class="borders" orientation="horizontal" >
<Label class="notification-label" text="Notification Center" ></Label>
<Image src="res://right_arrow" stretch="none" class="right-arrow" (tap)="onNotification()"></Image>
</StackLayout>
constructor(private routerExtensions: RouterExtensions) {
// ...
}
this.routerExtensions.navigate(["/NotificationPage"]);
我必须使用路径文件夹名称通知。我将第二页 NotificationComponent 放在 Notification 文件夹中 only.That 这就是我无法在页面之间导航的原因。
通过改变这个:
this.router.navigate(["NotificationPage"]);
对此:
this.router.navigate(["Notification"]);
解决了我的问题
这里有一个例子,我们可以在 img 标签上包含 routerLink-
<img src="../../../assets/images/Notification.png" [routerLink]="['/NotificationPage']" width="55%" height = "200px" class="img-responsive" style="margin-left: 220px">
我是 nativescript 的新手。我正在从警报页面导航到 导航页面。我已经发布了所有相关的codes.please检查它。
我没有得到任何 issue.When 执行图像 onClick 我可以调用此方法
onNotification()
。我可以看到这个控制台登录命令提示符
console.log("SteveCheck", "Test");
但是我不知道,为什么它没有移动到通知页面 单击警报中的按钮 page.Below 我已添加所有相关代码。
app.module.ts:
import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
import { AlertComponent } from "./AlertFolder/alert.component";
import { NativeScriptRouterModule } from "nativescript-angular/router"
import {AppRoutes, AppComponents } from "./app.routing";
@NgModule({
declarations: [AlertComponent, ...AppComponents],
bootstrap: [AlertComponent],
imports: [
NativeScriptModule,
NativeScriptRouterModule,
NativeScriptRouterModule.forRoot(AppRoutes)
],
schemas: [NO_ERRORS_SCHEMA],
})
export class AppModule {}
app.routing.ts:
import { AlertComponent } from "./AlertFolder/alert.component";
import { NotificationComponent } from "./Noficiation/notification";
export const AppRoutes:any = [
{ path: "", component: AlertComponent },
{ path: "NotificationPage", component: NotificationComponent}
];
export const AppComponents: any = [
AlertComponent,
NotificationComponent
];
alert.component.ts:
@Component({
selector: "sdk-child-component",
moduleId: module.id,
....
})
export class AlertComponent {
.....
.....
public constructor(private router: Router, private routerExtensions: RouterExtensions){
this.alertList = [];
}
onNotification() {
console.log("SteveCheck", "Test");
this.router.navigate(["NotificationPage"]);
}
}
alert.component.html:
<StackLayout class="borders" orientation="horizontal" >
<Label class="notification-label" text="Notification Center" ></Label>
<Image src="res://right_arrow" stretch="none" class="right-arrow" (tap)="onNotification()"></Image>
</StackLayout>
constructor(private routerExtensions: RouterExtensions) {
// ...
}
this.routerExtensions.navigate(["/NotificationPage"]);
我必须使用路径文件夹名称通知。我将第二页 NotificationComponent 放在 Notification 文件夹中 only.That 这就是我无法在页面之间导航的原因。
通过改变这个:
this.router.navigate(["NotificationPage"]);
对此:
this.router.navigate(["Notification"]);
解决了我的问题
这里有一个例子,我们可以在 img 标签上包含 routerLink-
<img src="../../../assets/images/Notification.png" [routerLink]="['/NotificationPage']" width="55%" height = "200px" class="img-responsive" style="margin-left: 220px">