标签: zone.js

当 rxjs 重新抛出 http 错误响应时,自定义全局错误处理程序不会被命中

目标:为服务器错误和应用程序错误(用 Typescript 代码生成)提供一个全局错误处理程序。

如何:从同一工作区中的 lib 项目提供自定义 ErrorHandler。这是我的库结构:

@common/错误处理库

我有以下 http-interceptor (http-error.interceptor.ts)

@Injectable()
export class HttpErrorInterceptor implements HttpInterceptor {

  constructor(@Inject(LOGGER_SERVICE) private logger: ILoggerService) {}

  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    return next.handle(req)
    .pipe(
        catchError( (error: HttpErrorResponse) => {
          console.log('error');

          return throwError(error);
        })
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

以下自定义全局错误处理程序(errors-handler.ts):

import { ErrorHandler, Injectable } from '@angular/core';

@Injectable()
export class ErrorsHandler implements ErrorHandler {

    handleError(error: any): void {
        console.log('hi!');
    }

}
Run Code Online (Sandbox Code Playgroud)

这是错误处理.module.ts

import { NgModule, ErrorHandler } from '@angular/core';
import { HTTP_INTERCEPTORS } from …
Run Code Online (Sandbox Code Playgroud)

error-handling typescript angular-http-interceptors zone.js angular

6
推荐指数
1
解决办法
6121
查看次数

使用 Visual Studio Code 调试器在 Nrwl.nx Angular 工作区中调试 Jest 测试

我正在使用 Visual Studio Code,并且我正在尝试在 Angular 的 Nrwl.Nx 工作区中调试 Jest 测试。

这是我迄今为止尝试过的:

启动文件

{
  "version": "0.2.0",
  "configurations": [

    {
      "type": "node",
      "request": "launch",
      "name": "Jest All Tests",
      "program": "${workspaceFolder}/src/Web/Finance/client-app/node_modules/.bin/jest",
      "args": ["--runInBand"],
      "cwd": "${workspaceFolder}/src/Web/Finance/client-app/apps/finance",
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "disableOptimisticBPs": true,
      "windows": {
        "program": "${workspaceFolder}/src/Web/Finance/client-app/node_modules/jest/bin/jest"
      }
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

app.component.spec.ts

import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
import 'zone.js/dist/zone.js';
import 'zone.js/dist/async-test.js';
import 'zone.js/dist/proxy.js';

describe('AppComponent', () => {
  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [AppComponent],
    }).compileComponents();
  }));
  it('should create …
Run Code Online (Sandbox Code Playgroud)

jestjs visual-studio-code zone.js angular nrwl-nx

6
推荐指数
0
解决办法
426
查看次数

在Angular 5中禁用zone.js后ngOnInit不会触发

我最近将Angular应用程序从4.3升级到5.0,并尝试使用其中的一些新功能。其中之一是从zone.js中删除依赖项。

main.ts:

platformBrowserDynamic().bootstrapModule(AppModule, {
  ngZone: 'noop',
});
Run Code Online (Sandbox Code Playgroud)

零件:

import { ApplicationRef, Component } from '@angular/core';
import { Router, NavigationEnd } from '@angular/router';
import { Subscription } from 'rxjs/Rx';

import { MenuService } from '../../services/menu.service';

@Component({
  selector: 'ba-menu',
  templateUrl: './baMenu.html',
  styleUrls: ['./baMenu.scss'],
})
export class BaMenu {
  menuItems: any[];
  protected _menuItemsSub: Subscription;
  protected _onRouteChange: Subscription;

  constructor(public _router: Router, public _service: MenuService, public app: ApplicationRef) {
    console.log('constructor triggered'); //This worked
    this.app.tick();
  }


  ngOnInit(): void {
    console.log('ngOnInit() triggered'); //This doesn't worked
    this._onRouteChange = …
Run Code Online (Sandbox Code Playgroud)

javascript angular2-changedetection zone.js angular angular5

5
推荐指数
1
解决办法
460
查看次数

替换 Nodejs 中的域?

我已阅读与此相关的多个线程,但他们有一点现在有点老了,这就是为什么作为Domain仍然是Deprecated到现在为止有没有人发现任何其他好的alternative使用Domain与否?

我读了这篇文章替代域 in-nodejs并且在那里我找到了zone.js,是否有人将它用作域替代?因为这个库的最后一次提交是在 3 年前,这就是为什么我认为它不是一个可靠的解决方案?

node.js zone.js

5
推荐指数
1
解决办法
2584
查看次数

拒绝诺言会引发“未捕获(在诺言中)”

我正在使用Promise处理模式对话框:当用户按下OK按钮时解决,在取消或关闭时拒绝。

为了解决和消除模态,我使用以下方法:

    let modalResolve, modalReject;
    modal.promise = new Promise<any>((resolve, reject) => {
        modalResolve = resolve;
        modalReject = reject;
    });
    modal.close = (result) => {
        if (modal.isOpen) {
            modalResolve(result);
        }
    };
    modal.dismiss = (reason) => {
        if (modal.isOpen) {
            modalReject(reason);
        }
    };
    modal.promise.finally(() => modalElement.remove());
Run Code Online (Sandbox Code Playgroud)

当取消按钮在模态内触发此方法时:

modal.dismiss('close')
Run Code Online (Sandbox Code Playgroud)

一切正常,并且模式隐藏,但是使用此描述和堆栈记录了控制台错误:

Error: Uncaught (in promise): close
    at resolvePromise (zone.js:814)
    at resolvePromise (zone.js:771)
    at eval (zone.js:873)
    at ZoneDelegate.invokeTask (zone.js:421)
    at Object.onInvokeTask (core.js:4751)
    at ZoneDelegate.invokeTask (zone.js:420)
    at Zone.runTask (zone.js:188)
    at drainMicroTaskQueue (zone.js:595)
    at ZoneTask.invokeTask [as invoke] …
Run Code Online (Sandbox Code Playgroud)

javascript promise zone.js angular

5
推荐指数
1
解决办法
2851
查看次数

为什么 Zone.js 改变 AngularJS 评估属性的方式?

我有一个同时包含 Angular (2+) 和 AngularJS (1.x) 的应用程序。我们正在使用第三方 AngularJS 库,该库在链接函数中从其 attrs 数组中读取对象,如下所示:

//3rd party lib code:
module.directive('test', () => ({
  template: `Look at the console`,
  link(elt, scope, attrs) {
    console.log('link attrs.props', attrs.props);
  }
})) 
Run Code Online (Sandbox Code Playgroud)

模板:

<!-- someObject = {name: 'foo'} -->
<test props="{{someObject}}"></test>
Run Code Online (Sandbox Code Playgroud)

我们刚刚升级到最新版本的 AngularJS,并注意到一个问题。通常,attrs.props 计算结果为对象的字符串表示形式。我们得到的不是字符串化对象,而是“[object Object]”

我尝试了最小化复制,但无法重现问题,直到我尝试导入 Zone.js,如您在此 stackblitz 上看到的: https ://stackblitz.com/edit/angularjs-attrs-test?file=app.js

如果导入了 Zone.js(Angular 2+ 需要它),那么attrs.props就是"[object Object]"。没有它,attrs.props就是{name: 'foo'}

这是一个已知的问题?有解决方法吗?

angularjs zone.js angular angular-hybrid

5
推荐指数
1
解决办法
1019
查看次数

未处理的承诺拒绝:超时;区域:角度6中的&lt;root&gt;

当ng-recaptcha组件路由到另一条路由时。

错误是:

未处理的承诺拒绝:超时;区域:任务:Promise.then; 值:超时未定义

在此处输入图片说明

如何解决此错误的人帮助。

recaptcha zone.js angular angular5 angular6

5
推荐指数
0
解决办法
1855
查看次数

Zone.js检测到ZoneAwarePromise`(window | global).Promise`已被自定义元素覆盖

我使用角度自定义元素功能(element.js)创建了一个小应用程序,将那个element.js文件导入到index.html中的另一个angular(parent)应用程序中,在开发服务器(ng serve)元素功能正常,但是在生产模式下(ng build --prod)在element.js文件中得到此错误。

@ angular / core“:”〜8.1.3“,@ angular / elements”:“ ^ 8.1.3”

element (angular custom element code)
polyfills.ts

import 'zone.js/dist/zone';  // Included with Angular CLI.
import "@webcomponents/custom-elements/src/native-shim";
import "@webcomponents/custom-elements/custom-elements.min";

app.module.ts
export class AppModule {
  constructor(private injector: Injector) { }

  ngDoBootstrap() {

    const el = createCustomElement(NotificationElementComponent, {
      injector: this.injector
    });
    // using built in the browser to create your own custome element name
    customElements.define('test-card', el);
  }
}


Run Code Online (Sandbox Code Playgroud)
angular (parent app)
index.html
<!doctype html>
<html lang="en">
<body>
    <app-root></app-root>
    <script src="./assets/elements.js"></script>
</body> …
Run Code Online (Sandbox Code Playgroud)

web-component zone.js angular angular-elements angular8

5
推荐指数
1
解决办法
896
查看次数

从 Angular 11.0.3 开始,e2e 测试会产生错误

从 11.0.3 Angular/Core 版本开始,E2E 测试不适用于具有默认配置的项目。

我打开了一个问题https://github.com/angular/angular/issues/40221但它似乎不是回归(?)

最小繁殖

https://github.com/BrunoBeraudPW/issue-angular-11.0.3

这是一个默认项目 Angular 11.0.3,我已将所有包更新到最新版本

我已经“手动”更新了所有软件包,因为“ng new”cmd 正在创建一个 Angular 10 应用程序,所以我想问题可能是由于其他软件包造成的。

但即使我刚刚更新了角度包,错误仍然存​​在

异常或错误

使用 fakeAsync 时:

Failed: zone-testing.js is needed for the async() test helper but could not be found.
Please make sure that your environment includes zone.js/dist/zone-testing.js
Run Code Online (Sandbox Code Playgroud)

selenium-webdriver 库中的几个错误(承诺)

C:\dev-phoenix\1-Photoweb-Forks\test\node_modules\selenium-webdriver\lib\promise.js:3067:27
              this.pending_ = {task: task, q: this.subQ_};
              task.promise.queue_ = this;
              result = this.subQ_.execute_(task.execute);
                                  ~
              this.subQ_.start();
            } catch (ex) {
Run Code Online (Sandbox Code Playgroud)

Internal/modules/cjs/loader.js 中的几个错误

internal/modules/cjs/loader.js:955:30
jasmine-spec-reporter: unable to open 'internal/modules/cjs/loader.js'
Error: ENOENT: no such file …
Run Code Online (Sandbox Code Playgroud)

jasmine protractor zone.js angular e2e

5
推荐指数
1
解决办法
2290
查看次数

测试 无法在resetFakeAsyncZone读取未定义的属性'assertPresent'

我对业力v1.4有问题。测试框架。我所有的单元测试现在都因错误而失败Cannot read property 'assertPresent' of undefined at resetFakeAsyncZone

我已经在寻找解决方案并对其进行了测试,但不幸的是,没有任何帮助。解决方案建议我应该更改test.js文件中的导入顺序。我已经做到了。

这是我正在使用的建议顺序,但仍然失败:

import 'zone.js/dist/zone.js'; // 1st
import 'zone.js/dist/async-test'; // 2nd
import 'zone.js/dist/fake-async-test'; // 3rd
import 'zone.js/dist/long-stack-trace-zone'; // 4th
import 'zone.js/dist/sync-test'; // 5th
import 'zone.js/dist/proxy.js'; // 6th
import 'zone.js/dist/jasmine-patch'; // 7th
Run Code Online (Sandbox Code Playgroud)

PS:我使用的是VS Code,它现在在保存文件时自动对导入进行排序,从而更改了我的自定义导入顺序,在这种情况下,这非常烦人。我不知道如何仅针对特定文件禁用它,因此我必须在记事本中编辑test.js文件。

testing karma-runner zone.js angular

4
推荐指数
2
解决办法
2643
查看次数