我可以将组件路由到特定页面吗?我想在like()过程完成后路由到某个地方
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, RouterModule, Routes } from '@angular/router';
import { GamesService } from '../games.service';
import { IGames } from '../games';
constructor(private router:Router, public route:ActivatedRoute, private gs:GamesService) { }
like(id:string,l:string){
if(l == 1){this.likes=0 }else{this.likes=1};
this.gs.like(id,this.likes).subscribe(
(data)=>{
// this.game=data;
console.log(data);
router.navigate(['wishlist'];
}
);
}
我收到此错误消息
Error: Can't resolve all parameters for DetailComponent: (?, [object Object], [object Object]).
答案 0 :(得分:0)
您拥有like
方法的组件(将其命名为Abc)
abc.component.ts
import { Router } from '@angular/router';
constructor(private router: Router) {
}
like(id:string,l:string) {
if (l == 1) {
this.likes=0;
} else {
this.likes=1;
}
this.gs.like(id,this.likes).subscribe((data) => {
console.log(data);
router.navigate(['otherComponentPath']); add this
});
}
abc.module.ts
import { RouterModule } from '@angular/router';
import { AbcComponent } from '<path to the component>';
import { AbcRoutingModule } from '<path to the abc routing module>';
@NgModule({
imports: [
...,
RouterModule,
AbcRoutingModule,
],
declarations: [
AbcComponent,
OtherComponent
]
})
export class AbcModule {
}
abcRouting.module.ts
const routes: Routes = [
...
path: 'otherComponentPath', //this will be in the url
component: OtherComponent
];
@NgModule({
imports: [ RouterModule.forChild(routes) ],
exports: [ RouterModule ]
})
export class AbcRoutingModule {
}
答案 1 :(得分:0)
在您的组件构造函数中,
typ, msg_ids = self.imap.uid('search', None, 'SUBJECT "#160496147"')
typ, msg_ids = self.imap.uid('search', None, 'SUBJECT "160496147"')
并按如下所示修改您的功能:
constructor(private _router: Router)