angular2 TypeError:无法设置未定义的属性“名称”

2023-12-28

我有一个 Angular2 项目,在 Mac OS 上创建并运行。但是当我在Windows上git它时,它无法运行。 在 Chrome 中,我收到此错误:

core.umd.js:3491 EXCEPTION: Uncaught (in promise): TypeError: Cannot set property 'name' of undefined
TypeError: Cannot set property 'name' of undefined
    at new EmptyError (http://localhost:3000/node_modules/rxjs/util/EmptyError.js:21:30)
    at FirstSubscriber._complete (http://localhost:3000/node_modules/rxjs/operator/first.js:148:31)
    at FirstSubscriber.Subscriber.complete (http://localhost:3000/node_modules/rxjs/Subscriber.js:114:18)
    at MergeAllSubscriber._complete (http://localhost:3000/node_modules/rxjs/operator/mergeAll.js:94:30)
    at MergeAllSubscriber.Subscriber.complete (http://localhost:3000/node_modules/rxjs/Subscriber.js:114:18)
    at MapSubscriber.Subscriber._complete (http://localhost:3000/node_modules/rxjs/Subscriber.js:132:26)
    at MapSubscriber.Subscriber.complete (http://localhost:3000/node_modules/rxjs/Subscriber.js:114:18)
    at EmptyObservable._subscribe (http://localhost:3000/node_modules/rxjs/observable/EmptyObservable.js:69:24)
    at EmptyObservable.Observable.subscribe (http://localhost:3000/node_modules/rxjs/Observable.js:45:27)
    at Observable._subscribe (http://localhost:3000/node_modules/rxjs/Observable.js:103:28)
    at MapOperator.call (http://localhost:3000/node_modules/rxjs/operator/map.js:54:23)
    at Observable.subscribe (http://localhost:3000/node_modules/rxjs/Observable.js:42:22)
    at Observable._subscribe (http://localhost:3000/node_modules/rxjs/Observable.js:103:28)
    at MergeAllOperator.call (http://localhost:3000/node_modules/rxjs/operator/mergeAll.js:63:23)
    at Observable.subscribe (http://localhost:3000/node_modules/rxjs/Observable.js:42:22)
core.umd.js:3496 ORIGINAL STACKTRACE:ErrorHandler.handleError @ core.umd.js:3496next @ core.umd.js:8449schedulerFn @ core.umd.js:4118SafeSubscriber.__tryOrUnsub @ Subscriber.ts:238SafeSubscriber.next @ Subscriber.ts:190Subscriber._next @ Subscriber.ts:135Subscriber.next @ Subscriber.ts:95Subject.next @ Subject.ts:61EventEmitter.emit @ core.umd.js:4104NgZone.triggerError @ core.umd.js:4465onHandleError @ core.umd.js:4426ZoneDelegate.handleError @ zone.js:246Zone.runGuarded @ zone.js:129_loop_1 @ zone.js:429drainMicroTaskQueue @ zone.js:438ZoneTask.invoke @ zone.js:349
core.umd.js:3497 Error: Uncaught (in promise): TypeError: Cannot set property 'name' of undefined
TypeError: Cannot set property 'name' of undefined
    at new EmptyError (EmptyError.ts:14)
    at FirstSubscriber._complete (first.ts:161)
    at FirstSubscriber.Subscriber.complete (Subscriber.ts:122)
    at MergeAllSubscriber._complete (mergeAll.ts:91)
    at MergeAllSubscriber.Subscriber.complete (Subscriber.ts:122)
    at MapSubscriber.Subscriber._complete (Subscriber.ts:144)
    at MapSubscriber.Subscriber.complete (Subscriber.ts:122)
    at EmptyObservable._subscribe (EmptyObservable.ts:74)
    at EmptyObservable.Observable.subscribe (Observable.ts:98)
    at Observable._subscribe (Observable.ts:158)
    at MapOperator.call (map.ts:50)
    at Observable.subscribe (Observable.ts:96)
    at Observable._subscribe (Observable.ts:158)
    at MergeAllOperator.call (mergeAll.ts:61)
    at Observable.subscribe (Observable.ts:96)
    at resolvePromise (zone.js:486) [angular]
    at resolvePromise (zone.js:471) [angular]
    at :3000de_modules/zone.js/dist/zone.js:520:17 [angular]
    at Object.onInvokeTask (core.umd.js:4396) [angular]
    at ZoneDelegate.invokeTask (zone.js:274) [angular]
    at Zone.runTask (zone.js:151) [<root> => angular]
    at drainMicroTaskQueue (zone.js:418) [<root>]
    at XMLHttpRequest.ZoneTask.invoke (zone.js:349) [<root>]ErrorHandler.handleError @ core.umd.js:3497next @ core.umd.js:8449schedulerFn @ core.umd.js:4118SafeSubscriber.__tryOrUnsub @ Subscriber.ts:238SafeSubscriber.next @ Subscriber.ts:190Subscriber._next @ Subscriber.ts:135Subscriber.next @ Subscriber.ts:95Subject.next @ Subject.ts:61EventEmitter.emit @ core.umd.js:4104NgZone.triggerError @ core.umd.js:4465onHandleError @ core.umd.js:4426ZoneDelegate.handleError @ zone.js:246Zone.runGuarded @ zone.js:129_loop_1 @ zone.js:429drainMicroTaskQueue @ zone.js:438ZoneTask.invoke @ zone.js:349
zone.js:405 Unhandled Promise rejection: TypeError: Cannot set property 'name' of undefined(…) ; Zone: angular ; Task: Promise.then ; Value: TypeError: Cannot set property 'name' of undefined(…) undefined

在 Firefox 中,我收到此错误:

EXCEPTION: Uncaught (in promise): TypeError: err is undefined
EmptyError@http://localhost:3000/node_modules/rxjs/util/EmptyError.js:21:9
    FirstSubscriber.prototype._complete@http://localhost:3000/node_modules/rxjs/operator/first.js:148:31
    Subscriber.prototype.complete@http://localhost:3000/node_modules/rxjs/Subscriber.js:114:13
    MergeAllSubscriber.prototype._complete@http://localhost:3000/node_modules/rxjs/operator/mergeAll.js:94:13
    Subscriber.prototype.complete@http://localhost:3000/node_modules/rxjs/Subscriber.js:114:13
    Subscriber.prototype._complete@http://localhost:3000/node_modules/rxjs/Subscriber.js:132:9
    Subscriber.prototype.complete@http://localhost:3000/node_modules/rxjs/Subscriber.js:114:13
    EmptyObservable.prototype._subscribe@http://localhost:3000/node_modules/rxjs/observable/EmptyObservable.js:69:13
    Observable.prototype.subscribe@http://localhost:3000/node_modules/rxjs/Observable.js:45:22
    Observable.prototype._subscribe@http://localhost:3000/node_modules/rxjs/Observable.js:10[…]
ORIGINAL STACKTRACE:  core.umd.js:3496:17
    resolvePromise@http://localhost:3000/node_modules/zone.js/dist/zone.js:486:31 [angular]
    resolvePromise@http://localhost:3000/node_modules/zone.js/dist/zone.js:471:17 [angular]
    scheduleResolveOrRejecthttp://localhost:3000/node_modules/zone.js/dist/zone.js:520:17 [angular]
    NgZone</NgZone.prototype.forkInnerZoneWithAngularBehavior/this.inner<.onInvokeTask@http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:4396:32 [angular]
    ZoneDelegate.prototype.invokeTask@http://localhost:3000/node_modules/zone.js/dist/zone.js:274:21 [angular]
    Zone.prototype.runTask@http://localhost:3000/node_modules/zone.js/dist/zone.js:151:28 [<root> => angular]
    drainMicroTaskQueue@http://localhost:3000/node_modules/zone.js/dist/zone.js:418:25 [<root>]
    ZoneTask/this.invoke@http://localhost:3000/node_modules/zone.js/dist/zone.js:349:25 [<root>]
core.umd.js:3497:17
Unhandled Promise rejection: TypeError: err is undefined
堆栈跟踪:
    [object Object] ; Zone: angular ; Task: Promise.then ; Value: TypeError: err is undefined
堆栈跟踪:
    [object Object] undefined  zone.js:405:13
Object { message: "Uncaught (in promise): TypeError: err is undefined
EmptyError@http://localhost:3000/node_modules/rxjs/util/EmptyError.js:21:9
    FirstSubscriber.prototype._complete@http://localhost:3000/node_modules/rxjs/operator/first.js:148:31
    Subscriber.prototype.complete@http://localhost:3000/node_modules/rxjs/Subscriber.js:114:13
    MergeAllSubscriber.prototype._complete@http://localhost:3000/node_modules/rxjs/operator/mergeAll.js:94:13
    Subscriber.prototype.complete@http://localhost:3000/node_modules/rxjs/Subscriber.js:114:13
    Subscriber.prototype._complete@http://localhost:3000/node_modules/rxjs/Subscriber.js:132:9
    Subscriber.prototype.complete@http://localhost:3000/node_modules/rxjs/Subscriber.js:114:13
    EmptyObservable.prototype._subscribe@http://localhost:3000/node_modules/rxjs/observable/EmptyObservable.js:69:13
    Observable.prototype.subscribe@http://localhost:3000/node_modules/rxjs/Observable.js:45:22
    Observable.prototype._subscribe@http://localhost:3000/node_modules/rxjs/Observable.js:103:16
    MapOpe"[…], originalStack: "ZoneAwareError@http://localhost:300…", zoneAwareStack: "resolvePromise@http://localhost:300…", stack: "resolvePromise@http://localhost:300…", rejection: TypeError, promise: Object, zone: Object, task: Object }

为什么? 这是我的代码:

应用程序模块.ts

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { CookieService } from 'angular2-cookie/core';
import './rxjs-operators';

import { LoginModule } from './login/login.module';
import { HomeModule } from './home/home.module';

import { AppComponent }  from './app.component';
import { LoadingComponent } from './loading/loading.component';
import { NavigationComponent } from './navigation/navigation.component';

import { LoginTransferService } from './service/transfer/login-transfer.service';

import { AppRoutingModule } from './app-routing.module';

import { AppRouteGuardsService } from './app-route-guards.service';


@NgModule({
    imports:      [
        BrowserModule,
        AppRoutingModule,
        LoginModule,
        HomeModule,
    ],
    declarations: [
        AppComponent,
        LoadingComponent,
        NavigationComponent,
    ],
    providers: [
        CookieService,
        AppRouteGuardsService,
        LoginTransferService
    ],
    bootstrap:    [ AppComponent ]
})
export class AppModule { }

应用程序组件.ts

import { Component } from '@angular/core';

import './rxjs-operators';

@Component({
    selector: 'my-app',
    template: `
        <ArrowIMWP-navigation></ArrowIMWP-navigation>
        <router-outlet></router-outlet>
    `,
    styleUrls: ['app/app.component.css']
})
export class AppComponent  {  } 

应用程序路由.module.ts

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { LoadingComponent } from './loading/loading.component';
import { AppRouteGuardsService } from './app-route-guards.service';

const routes: Routes = [{
    path: '',
    component: LoadingComponent,
    canActivate : [ AppRouteGuardsService ]
}];

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

应用程序路由守卫.service.ts

import { Injectable } from '@angular/core';
import {
    Router,
    CanActivate,
    ActivatedRouteSnapshot,
    RouterStateSnapshot
} from '@angular/router';
import { CookieService } from 'angular2-cookie/core';

@Injectable()
export class AppRouteGuardsService implements CanActivate {
    constructor(private cookieService:CookieService, private router:Router) {};

    canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
        let tempIsLogined = this.cookieService.getObject("ArrowIMWP-IsLogined");
        if (tempIsLogined && tempIsLogined == true) {
            if (state.url == "/") {
                this.router.navigate(['/home']);
                return false;
            }
            return true;
        }else {
            if (state.url == "/login") {
                return true;
            }
            this.router.navigate(['/login']);
            return false;
        }
    }
}

导航组件.ts

import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { CookieService } from 'angular2-cookie/core';
import { LoginTransferService } from '../service/transfer/login-transfer.service';

@Component({
    moduleId: module.id,
    selector: 'ArrowIMWP-navigation',
    templateUrl: 'navigation.component.html',
    styleUrls: ['navigation.component.css']
})

export class NavigationComponent implements OnInit {

    isShowNavigationItems = false;

    constructor(
        private router:Router,
        private cookieService:CookieService,
        private loginTransferService:LoginTransferService
    ) {
        let tempIsLogined = cookieService.getObject("ArrowIMWP-IsLogined");
        if (tempIsLogined && tempIsLogined == true) {
            this.isShowNavigationItems = true;
        }else {
            this.isShowNavigationItems = false;
        }

        loginTransferService.loginSuccessed$.subscribe(
            data => {
                console.log(data);
                if (data == "Logined") {
                    this.isShowNavigationItems = true;
                }
            }
        )
    }
}

登录模块.ts

import { NgModule } from '@angular/core';
import { BrowserModule }  from '@angular/platform-browser';
import { CookieService } from 'angular2-cookie/services/cookies.service';
import '../rxjs-operators';
import { LoginComponent } from './login.component';
import { LoginRoutingModule } from './login-routing.module';
import { LoginRouteGuardsService } from './login-route-guards.service';

@NgModule({
    imports:      [
        BrowserModule,
        LoginRoutingModule
    ],
    declarations: [ LoginComponent ],
    providers: [
        CookieService,
        LoginRouteGuardsService
    ],
    bootstrap:    [ LoginComponent ]
})

export class LoginModule {}

登录.组件.ts

import { Component, OnInit } from '@angular/core';
import { CookieService } from 'angular2-cookie/core';
import { Router } from '@angular/router';
import '../rxjs-operators';
import { LoginTransferService } from '../service/transfer/login-transfer.service';

@Component({
    moduleId: module.id,
    selector: 'ArrowIMWP-login',
    templateUrl: 'login.component.html',
    styleUrls : ['login.component.css']
})

export class LoginComponent implements OnInit {

    constructor(
        private cookieService:CookieService,
        private router:Router,
        private loginTransferService:LoginTransferService
    ) {}

    loginButtonClicked() {
        this.cookieService.putObject("ArrowIMWP-IsLogined", true);
        this.router.navigate(['/home']);
        this.loginTransferService.loginSuccessedNext("Logined");
    }
}

登录路由.module.ts

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { LoginComponent } from './login.component';
import { LoginRouteGuardsService } from './login-route-guards.service';

@NgModule({
    imports: [ RouterModule.forChild([{
        path: 'login',
        component: LoginComponent,
        canActivate : [ LoginRouteGuardsService ]
    }]) ],
    exports: [ RouterModule ]
})

export class LoginRoutingModule {}

登录路由守卫.service.ts

import { Injectable, OnInit } from '@angular/core';
import {
    Router,
    CanActivate,
    ActivatedRouteSnapshot,
    RouterStateSnapshot
} from '@angular/router';
import { CookieService } from 'angular2-cookie/core';

@Injectable()
export class LoginRouteGuardsService implements OnInit,CanActivate {
    constructor(private cookieService:CookieService, private router:Router) {};

    canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
        let tempIsLogined = this.cookieService.getObject("ArrowIMWP-IsLogined");
        if (tempIsLogined && tempIsLogined == true) {
            this.router.navigate(['/home']);
            return false;
        }else {
        return true;
        }
    }
}

你用过吗zone.js0.7.3 英寸package.json?如果是这样请更改为 0.7.2 尝试:

"zone.js": "0.7.2"

run npm install to try.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

angular2 TypeError:无法设置未定义的属性“名称” 的相关文章

随机推荐

  • 使用 wpf 中的自定义 TextElement 扩展 FlowDocument

    我想通过创建我自己的 Span 和 Run 衍生产品来扩展 FlowDocument 的功能 这可能吗 有人找到任何例子吗 微软没有公开渲染自定义所需的方法文本元素 http msdn microsoft com en us library
  • WildFly (JBoss) 下的 JTDS 模块

    我正忙着从 JBoss 7 1 1 升级到 Wildfly 8 0 0 Beta1 我在 JBoss 下使用 JTDS 数据库驱动程序没有问题 但它在 WildFly 下无法工作 我已经创建了 net sourceforge jtds ma
  • Pycharm - 在调试器中启用自动换行

    例如 在 Pycharm 2017 3 的调试器中 当我打印一本大字典时 它全部在一行上 我希望这本词典能够换行 这样我就可以看到更多内容 我相信以前版本的 PyCharm 具有这种包装行为 我查看了设置 只能找到编辑器的自动换行 For
  • 如何知道MKMapView的visibleMapRect是否包含坐标?

    如果我有 MKMapView 和 CLLocationCooperative2D 如何测试地图的可见区域是否包含坐标 最快的方法是使用内置的苹果功能 这将使此类事情变得超级快 if MKMapRectContainsPoint mapVie
  • 附加操作按钮在 Flask-admin 上不起作用

    我正在尝试向 Flask admin 表单添加一项操作 它必须增加评级 1 并且它适用于批量操作 但不适用于单个操作 请帮我找到这个错误 我花了很多时间试图让这个东西正常工作 这是代码 我在 templates 文件夹中制作了一个 html
  • 我可以更改 Azure Function Event Hub 触发器启动检查点吗?

    当我使用新的消费者组建立一个新的 Azure Function 来侦听我们的事件中心时 它会获取曾经发送到事件中心的所有消息 甚至是几个月前的消息 我认为将集线器上的消息保留设置为一天会限制这一点 但显然不是 不管怎样 我真的只希望新的 A
  • 收到“未安装 qmlscene”。 “Ubuntu”上“QT CREATOR”中的警告

    我将 QTStatic 添加到 QT 版本 但我无法使用此版本在套件选项卡中构建和设置 我上传了下面的屏幕截图 请帮助 版本选项卡屏幕截图 https i stack imgur com rpaGB jpg 套件选项卡屏幕截图 https
  • 如何在 Rails 视图中呈现所有评论?

    我是 Rails 新手 所以放轻松 我创建了一个博客 我已成功实施评论并将其附加到每个帖子中 现在 我想在侧边栏中显示所有帖子的最新评论列表 我认为这里涉及两件事 对comment controller rb的更新 然后是从实际页面的调用
  • postgresql - 替换文本字段中字符串的所有实例

    在 postgresql 中 如何替换数据库列中字符串的所有实例 假设我想替换所有实例cat with dog 例如 最好的方法是什么 你想使用 postgresql 的replace http www postgresql org doc
  • Ant 任务

    我现在看到 Ant 既有
  • 如何访问iOS中的弱链接框架?

    我想在 iOS 5 上使用 Twitter 框架 但能够在旧操作系统中运行我的应用程序 我在 Xcode 4 2 Target 设置中添加了弱引用框架 即设置 可选 标志 基础 SDK 是 iOS 5 iOS 部署目标是 iOS 3 2 接
  • 如何将第三方 npm 包与 ember cli 应用程序一起使用

    EDIT 这实际上是关于任何不适合与 ember 一起使用的 npm 包 就我而言 我尝试让 crypto js 工作 但对于任何不是专门为 ember cli 设计的 npm 包来说 似乎总是遇到同样的问题 我想在我的 ember 应用程
  • Python 错误代码已升级

    考虑一个 python 脚本 error py import sys sys exit 3 Invoking python error py echo 产生预期的 3 但是 考虑 runner py import os result os
  • 在 Android 应用程序中使用个人证书

    我希望用户能够在从生成证书的网站安装后将他们自己的个人证书安装到我的 Android 应用程序中 但是当我使用 WebClient 或 Android 浏览器浏览它时 安全存储会弹出并安装它 在版本 14 Android 4 0 之前 AP
  • 带返回值的动态 Linq 表达式

    我需要创建一个动态 linq 表达式 然后我开始使用许多示例 我测试了一些工作 有些没有 在这种情况下 我想创建一个如下所示的方法 public bool Check int intvar if i gt 2 return true els
  • Laravel 4:调用未定义的方法 Redis::connection()

    我对这个错误快要疯了 我有一个 Debian 7 的 vagrant VM 用 Puphpet 生成 安装得很好 1 Redis已安装并运行 redis server在跑 我可以使用服务器127 0 0 1 6379 2 安装php5 re
  • Code First:Fluent api 会影响 UI 吗?

    我正在读 Julie Lerman 写的一本关于 Code First 的书 根据这本书 注释和 Fluent api 给出相同的结果 一切都取决于开发人员的风格 我知道注释允许配置代码如何首先生成数据库对象以及 MVC 如何自定义 UI
  • 点击事件后关闭汉堡菜单

    我有一个汉堡菜单 几乎完整 只有 1 个我无法弄清楚的错误 问题 我的导航链接到主页上的不同区域 因此 在主页上 用户可以单击导航链接 这将立即将他们带到页面上的所需位置 我的问题是因为没有加载 所以一旦用户单击导航链接 他们就会被带到该位
  • 使用 secure_random 在 rspec 中存根随机值

    我正在尝试为我的 gem 编写规范 它生成 otp 并将其保存在数据库中 现在我正在为其编写规格 所以基本上我有三种方法generate otp regenerate otp verify otp otp what generate otp
  • angular2 TypeError:无法设置未定义的属性“名称”

    我有一个 Angular2 项目 在 Mac OS 上创建并运行 但是当我在Windows上git它时 它无法运行 在 Chrome 中 我收到此错误 core umd js 3491 EXCEPTION Uncaught in promi