0

我在重新加载 childComponent 函数时遇到问题。我有一个组件根据接收到的参数对数据库进行查询。当我第一次访问此路由时,它很好地执行了 OnInit 函数,但如果我更改参数:page,它不会做任何事情。

这是组件:

//temas.children.component.ts
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';

@Component({
  selector: 'app-temas-children',
  templateUrl: './temas-children.component.html',
  styleUrls: ['./temas-children.component.css']
})
export class TemasChildrenComponent implements OnInit {


  constructor(private route: ActivatedRoute) { }

  ngOnInit() {
     console.log(this.route.snapshot.data.temas);

  }
}

路线:

//app.routes.ts
//imports and some other routes
{ path: 'temas/:categoria', component: TemasComponent, children:[
{path: ':page', component: TemasChildrenComponent, runGuardsAndResolvers: "always", resolve:{temas: TemasResolverService}}
]},

解析服务:

//temas.resolver.service.ts
import { Injectable } from '@angular/core';
import { CrudService } from './crud.service';
import { Resolve } from '@angular/router';
import { ActivatedRouteSnapshot } from '@angular/router';

@Injectable({
  providedIn: 'root'
})
export class TemasResolverService implements Resolve<any>{

constructor(private crudService: CrudService) { }
  resolve(route:ActivatedRouteSnapshot){
    return this.crudService.getTemas(route.parent.pathFromRoot[1].params.categoria, route.paramMap.get('page'));
  }
}
4

0 回答 0