![](/img/trans.png)
[英]Uncaught (in promise): TypeError: Cannot read property 'get' of undefined in angular2+
[英]Angular 2 Uncaught (in promise): TypeError: Cannot read property 'isActivated' of undefined
如果我返回到相同的路由路徑,則會顯示錯誤
“Uncaught(承諾):TypeError:無法讀取未定義的屬性'isActivated'”。
但不是第一次出現。 誰能幫我 ?
const mainRoutes: Routes = [
{ path: '', pathMatch: 'full', redirectTo: '/home' },
{
path: 'home', loadChildren: './apps/home/home.module#HomeModule', canActivate: [AuthGuard],
resolve: {
crisis: NavigarionResolve
}
}
{ path: '**', component: PageNotFoundComponent }
];
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() {
}
}
this.router.navigate(['/home']);
對我來說,問題是正在加載的應用程序的第二個實例。 這是由“control”組件中的templateUrl無效引起的。
我將一個微調器組件從app/components/client/spinner.component
到app/components/shared/spinner.component
但忘記更新templateUrl。
這意味着我的微調器正在使用錯誤的html加載到我的其他組件中。 我在module.ts
使用了組件的正確路徑,因此它沒有拋出任何構建錯誤,但是當它找不到spinner.component.html時,mvc6返回了默認的索引頁面,所以它試圖從組件內部加載整個應用程序。 當我的內容加載后,一旦移除了微調器,就會移除這個內部應用程序。
我不完全理解它,但由於應用程序從內部再次加載,似乎路由器出現了某種沖突。 在我的情況下,我很幸運地注意到我的應用程序是故障,所以我在故障部分暫停了javascript並掃描了html,並注意到我的微調器內有一個<html>
標簽。
嘗試在app.component類中設置一個斷點 ,看看它是否被命中兩次,或者在控制台中運行document.getElementsByTagName("my-app")
(或者調用你的app.component),如果你有多於1個返回的元素你應該能夠從那里調試問題。 在我的情況下,這僅在微調器顯示時顯示,因此如果您的頁面上有組件進出,請嘗試打破每個顯示/隱藏。
您的問題在github上討論,看起來像組件依賴問題,以下鏈接可以幫助您:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.