目标:为服务器错误和应用程序错误(用 Typescript 代码生成)提供一个全局错误处理程序。
如何:从同一工作区中的 lib 项目提供自定义 ErrorHandler。这是我的库结构:
我有以下 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
我正在使用 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) 我最近将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
我已阅读与此相关的多个线程,但他们有一点现在有点老了,这就是为什么作为Domain
仍然是Deprecated
到现在为止有没有人发现任何其他好的alternative
使用Domain
与否?
我读了这篇文章替代域 in-nodejs并且在那里我找到了zone.js,是否有人将它用作域替代?因为这个库的最后一次提交是在 3 年前,这就是为什么我认为它不是一个可靠的解决方案?
我正在使用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) 我有一个同时包含 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'}
。
这是一个已知的问题?有解决方法吗?
我使用角度自定义元素功能(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) 从 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) 我对业力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文件。
zone.js ×10
angular ×9
angular5 ×2
javascript ×2
angular6 ×1
angular8 ×1
angularjs ×1
e2e ×1
jasmine ×1
jestjs ×1
karma-runner ×1
node.js ×1
nrwl-nx ×1
promise ×1
protractor ×1
recaptcha ×1
testing ×1
typescript ×1