简体   繁体   English

Angular 2 Uncaught(承诺):TypeError:无法读取未定义的属性'isActivated'

[英]Angular 2 Uncaught (in promise): TypeError: Cannot read property 'isActivated' of undefined

If I return to the same routing path it show an error 如果我返回到相同的路由路径,则会显示错误

"Uncaught (in promise): TypeError: Cannot read property 'isActivated' of undefined". “Uncaught(承诺):TypeError:无法读取未定义的属性'isActivated'”。

But not show at first time. 但不是第一次出现。 can any one help me ? 谁能帮我 ?

routing 路由

const mainRoutes: Routes = [
    { path: '', pathMatch: 'full', redirectTo: '/home' },
    {
        path: 'home', loadChildren: './apps/home/home.module#HomeModule', canActivate: [AuthGuard],
        resolve: {
            crisis: NavigarionResolve
        }
    }
    { path: '**', component: PageNotFoundComponent }
];

Component 零件

import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { AuthService }            from '../main/service/auth.service';

@Component({
  selector: 'home-app',
  templateUrl: 'apps/home/view/home.component.html',
  providers: [AuthService]
})

export class HomeComponent implements OnInit {
  loaded: boolean = false;
  title = 'Customer Management Home';
  slogan = 'Hi ...Home ';
  views: Object[] = [];
  constructor(private _authService: AuthService, private router: Router) {
    this.views = [
      {
        name: "My Account",
        description: "Edit my account information",
        icon: "assignment ind"
      },
      {
        name: "Potential dates",
        description: "Find your soulmate!",
        icon: "pets"
      }
    ];

  }
  logout() {
    this._authService.logout().then(() => {
      this.router.navigate(['/login']);
    });
  }

  ngOnInit() {

  }
}

Navigarion Navigarion

 this.router.navigate(['/home']);

For me the issue was a second instance of the app being loaded. 对我来说,问题是正在加载的应用程序的第二个实例。 This was caused by an invalid templateUrl within a "control" component. 这是由“control”组件中的templateUrl无效引起的。

I moved a spinner component I have from app/components/client/spinner.component to app/components/shared/spinner.component but forgot to update the templateUrl. 我将一个微调器组件从app/components/client/spinner.componentapp/components/shared/spinner.component但忘记更新templateUrl。
This meant that my spinner was loading up inside my other components with the wrong html. 这意味着我的微调器正在使用错误的html加载到我的其他组件中。 I had used the correct path for the component in module.ts , so it wasn't throwing any build errors, but when it couldn't find the spinner.component.html, mvc6 was returning the default index page, so it tried to load up the entire app from inside the component. 我在module.ts使用了组件的正确路径,因此它没有抛出任何构建错误,但是当它找不到spinner.component.html时,mvc6返回了默认的索引页面,所以它试图从组件内部加载整个应用程序。 This inner app was then being removed once the spinner was removed as my content had loaded. 当我的内容加载后,一旦移除了微调器,就会移除这个内部应用程序。

I don't fully understand it, but it appears the router was having some sort of conflict due to the app being loaded again from inside itself. 我不完全理解它,但由于应用程序从内部再次加载,似乎路由器出现了某种冲突。 In my case, I was lucky enough to notice that my app was glitching, so I paused javascript during the glitchy part and scanned the html, and noticed there was a <html> tag inside my spinner. 在我的情况下,我很幸运地注意到我的应用程序是故障,所以我在故障部分暂停了javascript并扫描了html,并注意到我的微调器内有一个<html>标签。

Try setting a breakpoint inside your app.component class and seeing if it gets hit twice, or running document.getElementsByTagName("my-app") (or whatever your app.component is called) in the console and if you have more than 1 element returned you should be able to debug the problem from there. 尝试在app.component类中设置一个断点 ,看看它是否被命中两次,或者在控制台中运行document.getElementsByTagName("my-app") (或者调用你的app.component),如果你有多于1个返回的元素你应该能够从那里调试问题。 In my case this only showed while the spinner was showing, so if you have components coming and going on your page, try breaking on each one show/hiding. 在我的情况下,这仅在微调器显示时显示,因此如果您的页面上有组件进出,请尝试打破每个显示/隐藏。

Your problem is discussed at github, looks like the component dependency issue, the following link may help you: 您的问题在github上讨论,看起来像组件依赖问题,以下链接可以帮助您:

Uncaught (in promise): TypeError: Cannot read property 未捕获(承诺):TypeError:无法读取属性

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获(承诺):类型错误:无法读取 angular2+ 中未定义的属性“get” - Uncaught (in promise): TypeError: Cannot read property 'get' of undefined in angular2+ 未捕获(承诺):类型错误:无法读取角度 10 中未定义的属性“ɵcmp” - Uncaught (in promise): TypeError: Cannot read property 'ɵcmp' of undefined in angular 10 Angular 2-未捕获(承诺):TypeError:无法读取未定义的属性“ title” - Angular 2 - Uncaught (in promise): TypeError: Cannot read property 'title' of undefined 角度7-错误错误:未捕获(承诺):TypeError:无法读取未定义的属性“ map” - Angular 7- ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'map' of undefined Angular 7 - 错误错误:未捕获(承诺):类型错误:无法读取未定义的属性“forEach” - Angular 7 - ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'forEach' of undefined 未捕获(承诺中):TypeError:无法读取未定义的属性“userSubject”类型错误:无法读取未定义的属性“userSubject” - Uncaught (in promise): TypeError: Cannot read property 'userSubject' of undefined TypeError: Cannot read property 'userSubject' of undefined 错误错误:未捕获(承诺):TypeError:无法读取未定义的属性“ map” - ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'map' of undefined 未捕获(承诺):类型错误:无法读取 ionic3 中未定义的属性“调用” - Uncaught (in promise): TypeError: Cannot read property 'call' of undefined in ionic3 未捕获(承诺):TypeError:无法读取未定义的属性“ router” - Uncaught (in promise): TypeError: Cannot read property 'router' of undefined 错误:未捕获(承诺):TypeError:无法读取未定义的属性“ customerName” - Error: Uncaught (in promise): TypeError: Cannot read property 'customerName' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM