angular关于本页路由不刷新

angular关于本页路由不刷新_第1张图片

代码如下

<div class="content col-md-12">
  <div class="title">
    <span>已选择2项span>
    <a class="btn btn-info">批量添加a>
    <a class="btn btn-info" [routerLink]="['schspAddschsp']">新增a>
  div>

  <div class="row">
    <table class="table table-bordered" >
      <thead>
      <tr>
        <th>th>
        <th>序号th>
        <th>运动队th>
        <th>竞赛名称th>
        <th>教练员th>
        <th>队长th>
        <th>状态th>
        <th>备注th>
        <th>操作th>
      tr>
      thead>
      <tbody>
      <tr *ngFor="let svlist of svlists let i = index" >
        <td><input type="checkbox">td>
        <td>{{i+1}}td>
        <td>{{svlist.equipe}}td>
        <td>{{svlist.name}}td>
        <td>{{svlist.coach}}td>
        <td>{{svlist.leader}}td>
        <td>{{svlist.status}}td>
        <td>{{svlist.remark}}td>
        <td>
          <a class="btn alink" [routerLink] = "['schspSchspinfo',svlist.uid]" title="查看">查看<i class="fa fa-search">i>a>
          <a class="btn alink" [routerLink] = "['schspEditschsp',svlist.uid]">编辑a>
        td>
      tr>
      tbody>
    table>
  div>
  <router-outlet>router-outlet>
div>
这是需要点击刷新的页面

<div class="row schsp_schsp">
  <table class="table table-bordered" >
    <thead>
    <tr>
      <th>序号th>
      <th>学生姓名th>
      <th>学号th>
      <th>团体/个人th>
      <th>国家级/市级th>
      <th>名次th>
      <th>是否破纪录th>
      <th>奖励金额th>
      <th>状态th>
      <th>操作th>
    tr>
    thead>
    <tbody>
    <tr *ngFor="let inf of infor" >
      <td>{{inf.id}}td>
      <td>{{inf.cname}}td>
      <td>{{inf.username}}td>
      <td>{{inf.groupOrindividual}}td>
      <td>{{inf.level}}td>
      <td>{{inf.rank}}td>
      <td>{{inf.breaking}}td>
      <td>{{inf.reword}}td>
      <td>{{inf.state}}td>
      <td>
        
        
      td>
    tr>
    tbody>
  table>
  <a class="btn determine_close" οnclick="javascript:history.back(-1);">关闭a>
div>


ngOnInit() {
  this.id = this.routeInfo.snapshot.params["id"];
  this.infor = this.eventListService.getInforById(this.id);
  //    this.eventListService.getInforById(this.id).subscribe(
  //   infor => this.infor = infor
  // );
  this.inforlists = this.eventListService.getInforlist();

  $(".determine_close").click(function() {
      $(".schsp_schsp").hide();
    }
  );
}

ngDoCheck() {
  this.id = this.routeInfo.snapshot.params["id"];
  this.infor = this.eventListService.getInforById(this.id);
  //    this.eventListService.getInforById(this.id).subscribe(
  //   infor => this.infor = infor
  // );
}
如图,只需要在该页面添加一个DoCheck的钩子,下次点击,不再走OnInit,将需要刷新的代码放在DoCheck中即可。

你可能感兴趣的:(前端,angular,angular)