ViewDestroyedError:尝试使用已损坏的视图:路由到主目录时,detectChanges

时间:2019-08-20 14:27:47

标签: angular7

错误错误:“ ViewDestroyedError:尝试使用已破坏的视图:detectChanges”     角度14 HeaderComponent.html:3:48

我的标题组件

import { Component, OnInit } from '@angular/core';
import { AuthserviceService } from '../services/authservice.service';

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

   constructor(public _auth:AuthserviceService) { }

  ngOnInit() {

  }



}

我的标头组件html

<div class="navbar navbar-expand-lg fixed-top navbar-dark bg-black">
    <div class="container">
      <div class="float-left" style="width:25%">
<a routerLink="/" class="nav-link text-white" >
<img src="assets/images/offerinthecity2.png" class="img-responsive" style="max-width:200px">
</a>
</div>
      <div class="float-right text-right" style="width:20%" *ngIf="_auth.loggedIn()">
          <a class="nav-link btn btn-primary" routerLink="/dashboard">Dahboard</a>

      </div>
      <div class="float-right text-right" style="width:20%"  *ngIf="_auth.loggedIn()">
        <a class="nav-link btn btn-primary" style="cursor: pointer; color:#fff;" (click)="_auth.logoutuser()">Logout</a>
      </div>
      <div class="float-right text-right" style="width:20%">

        <a class="nav-link btn btn-primary" routerLink="/post">POST YOUR OFFERS →</a>

      </div>
    </div>
  </div>

应用程序路由模块ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from './home/home.component';
import { LoginComponent } from './login/login.component';
import { PostComponent } from './post/post.component';
import { EditpostComponent } from './editpost/editpost.component';
import { NotfoundComponent } from './notfound/notfound.component';
import { OtpComponent } from './otp/otp.component';
import { DashboardComponent } from './dashboard/dashboard.component';
import { from } from 'rxjs';
import { AuthGuard } from './auth.guard';


const routes: Routes = [
  {
    path: '',
    component: HomeComponent
  },

  {
    path: 'home',
    component: HomeComponent
  },
  {
    path: 'login',
    component: LoginComponent
  },
  {
    path: 'otp/:id',
    component:OtpComponent

  },
  {
    path: 'post',
    component: PostComponent,
    canActivate:[AuthGuard]

  },
  {
    path: 'post/:id',
    component: EditpostComponent,
    canActivate:[AuthGuard]

  },
  {
    path: 'dashboard',
    component: DashboardComponent,
    canActivate:[AuthGuard]

  },

  { 
    path: '404',
    component: NotfoundComponent 
  },
  { 
    path: '**', 
    component: NotfoundComponent 
 }



];

@NgModule({
  imports: [RouterModule.forRoot(routes , { useHash: true })],
  exports: [RouterModule]
})
export class AppRoutingModule { }

我的app.component.html


<app-header></app-header>

  <div class="container-fluid">
      <div class="row">
          <router-outlet></router-outlet>
      </div>
    </div>


<app-footer></app-footer>

从邮政路线重定向到本国路线时。 找不到所需的任何解决方案帮助。 我想知道为什么我是新手,所以我自己也无法弄清楚

0 个答案:

没有答案