显然throwError(error)现在已被弃用。VS Code 的 IntelliSense 建议throwError(() => new Error('error')。new Error(...)仅接受字符串。在不破坏我的情况下更换它的正确方法是什么HttpErrorHandlerService ?
import { Injectable } from '@angular/core';\nimport {\n HttpEvent,\n HttpInterceptor,\n HttpHandler,\n HttpRequest,\n HttpErrorResponse,\n HttpResponse,\n HttpHeaders\n} from '@angular/common/http';\nimport { Observable, EMPTY, finalize, catchError, timeout, map, throwError } from 'rxjs';\n\nimport { HttpErrorHandlerService } from '@core/services';\n\n@Injectable()\nexport class HttpErrorInterceptor implements HttpInterceptor {\n private readonly APP_XHR_TIMEOUT = 6000;\n\n constructor(private errorHandlerService: HttpErrorHandlerService) {}\n\n intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {\n return next.handle(this.performRequest(request)).pipe(\n timeout(this.APP_XHR_TIMEOUT),\n map((event: HttpEvent<any>) => this.handleSuccessfulResponse(event)),\n catchError((error: …Run Code Online (Sandbox Code Playgroud) 我创建一个自定义 Angular 材质模块,material.module.ts 文件,并在此文件中导入以下 Angular 材质 UI 组件,如下所示。
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import {
MatButtonModule,
MatToolbarModule,
MatIconModule,
MatBadgeModule,
MatSidenavModule,
MatListModule,
MatGridListModule,
MatFormFieldModule,
MatInputModule,
MatSelectModule,
MatRadioModule,
MatDatepickerModule,
MatNativeDateModule,
MatChipsModule,
MatTooltipModule,
MatTableModule,
MatPaginatorModule
} from '@angular/material';
@NgModule({
imports: [
CommonModule,
MatButtonModule,
MatToolbarModule,
MatIconModule,
MatSidenavModule,
MatBadgeModule,
MatListModule,
MatGridListModule,
MatFormFieldModule,
MatInputModule,
MatSelectModule,
MatRadioModule,
MatDatepickerModule,
MatNativeDateModule,
MatChipsModule,
MatTooltipModule,
MatTableModule,
MatPaginatorModule
],
exports: [
MatButtonModule,
MatToolbarModule,
MatIconModule,
MatSidenavModule,
MatBadgeModule,
MatListModule,
MatGridListModule,
MatInputModule,
MatFormFieldModule,
MatSelectModule,
MatRadioModule,
MatDatepickerModule,
MatChipsModule,
MatTooltipModule, …Run Code Online (Sandbox Code Playgroud) 我正在将我的应用程序从 Angular v11 升级到 Angular v12。当我尝试升级 Angular 包时出现此错误:
ng update @angular/core@12 @angular/cli@12
Run Code Online (Sandbox Code Playgroud)
Migration failed: Incompatible peer dependencies found
Package has an incompatible peer dependency to "@angular/common" (requires "^8.1.3 || ^9.0.0" (extended), would install "12.0.0").
Package has an incompatible peer dependency to "@angular/core" (requires "^8.1.3 || ^9.0.0" (extended), would install "12.0.0").
Run Code Online (Sandbox Code Playgroud)
这些只是警告,但迁移因此而失败。
我可以选择使用该--force选项来忽略不兼容的对等依赖项并稍后解决这些警告。我应该这样做吗?如果我这样做,会破坏具有不兼容对等依赖项的包吗?
将我的 Angular 6 项目迁移到 12 后。\n我在终端中收到多个警告
\n如果在 angular.json 中我设置了 optimization: false 配置,那么所有问题都会得到解决,但我不想进行此更改,它应该只是 true 。
\n经过优化:是的,我收到所有这些警告:-
\n早期相同的代码运行良好,没有任何警告。
\nassets/.../variables.scss - Warning: Css Minimizer Plugin: > assets/.../variables.scss:6:0: warning: Unexpected "$"\n 6 \xe2\x94\x82 $color-normal-gray:#8a8a8a;\n \xe2\x95\xb5 ^\n\nassets/.../global.scss - Warning: Css Minimizer Plugin: > \nassets/.../global.scss:285:2: warning: Expected identifier but found "."\n 285 \xe2\x94\x82 .dropdown-menu{\n \xe2\x95\xb5 ^\n\nassets/.../global.scss - Warning: Css Minimizer Plugin: > \nassets/.../global.scss:255:6: warning: Expected identifier but found "*"\n 255 \xe2\x94\x82 *background-color: #d9d9d9;\n \xe2\x95\xb5 ^\n\nassets/.../master.scss - Warning: Css Minimizer Plugin: > \nassets/.../master.scss:567:8: …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Angular 12 中添加 Bootstrap 5 下拉列表,但它不起作用。
我已经安装了所有必需的软件包,并将它们添加到angular.json文件中。
从 Bootstrap 5 文档复制了确切的示例,但仍然不起作用。
在angular.json我已经给出
"styles": [
"node_modules/bootstrap/dist/css/bootstrap.min.css"
],
"scripts": [
"node_modules/jquery/dist/jquery.min.js",
"node_modules/popper.js/dist/umd/popper.min.js",
"node_modules/bootstrap/dist/js/bootstrap.min.js"
]
Run Code Online (Sandbox Code Playgroud)
下面是我的 HTML 代码(与 Bootstrap 5 文档中的相同)
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton1" data-
bs-toggle="dropdown" aria-expanded="false">
Dropdown button
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
我使用命令npm i来安装软件包,但没有提及任何版本名称,所以我猜安装了最新版本。安装 jQuery 作为最后的手段读到 Bootstrap 5 不需要 jQuery。任何帮助是极大的赞赏。
将Angular 10项目升级到Angular 12。但是现在在运行生产构建时,它给出了错误
索引 HTML 生成失败。
未定义:6:720366 缺少 '}'
ng build --configuration production --aot
Run Code Online (Sandbox Code Playgroud)
很难找到错误,因为它指向生成的 HTML 文件。节点日志不会做太多事情。
的内容 index.html
<!doctype html>
<html lang="en">
<head>
<title>Quiz - Admin</title>
<base href="/">
<meta charset="utf-8">
</head>
<body>
<app></app>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
在运行开发构建时,本地不报错,甚至ng build成功完成
请在此处检查构建管道:https : //github.com/anuj9196/quiz-app/runs/2589355739?check_suite_focus= true#step:7: 56
我们最近升级到Angular 12并面临浏览器源映射丢失的问题,因此我们无法调试我们的组件文件,因为没有任何组件文件。谁能建议我缺少什么?
我在本地和建筑项目中有 Angular 12,它运行良好,没有任何错误。
我的本地设置:
Angular CLI: 12.0.5
Node: 12.16.3
Package Manager: npm 6.14.4
OS: win32 x64
Angular: 12.0.5
Run Code Online (Sandbox Code Playgroud)
但是,当在 Linux 服务器上构建我的项目时,它给出了这个错误,没有什么可处理的。
服务器设置:
Angular CLI: 12.0.5
Node: 14.18.1
Package Manager: npm 6.14.15
OS: linux x64
Angular: 12.0.5
Run Code Online (Sandbox Code Playgroud)
Error: src/app/app-routing.module.ts:34:14 - error NG6002: Appears in the NgModule.imports of AppModule, but itself has errors
34 export class AppRoutingModule { }
Run Code Online (Sandbox Code Playgroud)
应用程序模块.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } …Run Code Online (Sandbox Code Playgroud) 将 Angular 从 v.11 升级到 v.12 后,我收到以下警告:
警告:在项目的浏览器列表配置中请求支持 IE 11。自 Angular v12 起不推荐使用 IE 11 支持。有关更多信息,请参阅https://angular.io/guide/browser-support
我的项目中没有浏览器列表。并且在polyfill.ts与 IE 相关的所有内容中都被注释掉了。Angular 从哪里推断出这个请求?
我已将我的项目从 Angular 12 更新为 Angular 13,但遇到此错误:
Error: node_modules/@types/ws/index.d.ts:328:18 - error TS2315: Type 'Server' is not generic.
328 server?: HTTPServer<V> | HTTPSServer<V> | undefined;
~~~~~~~~~~~~~
Error: node_modules/@types/ws/index.d.ts:328:34 - error TS2315: Type 'Server' is not generic.
328 server?: HTTPServer<V> | HTTPSServer<V> | undefined;
~~~~~~~~~~~~~~
Run Code Online (Sandbox Code Playgroud)
我尝试安装npm i @types/ws但没有成功。
angular ×10
angular12 ×10
typescript ×5
javascript ×3
angular13 ×1
bootstrap-5 ×1
build ×1
html ×1
node.js ×1
rxjs ×1