我使用 ng-bootstrap 以 angular 开始了我的第一个项目,并按照安装过程进行了操作,但是它不起作用。
该消息是“未捕获的错误:您的应用程序或其依赖项之一似乎正在使用i18n.
Angular 9 引入了一个$localize()需要加载的全局函数。请添加import '@angular/localize';到您的 polyfills.ts 文件中。”
然后我在 polyfill.ts 中添加了这一行
import '@angular/localize';
Run Code Online (Sandbox Code Playgroud)
现在消息变成了
未找到 ./src/polyfills.ts 模块中的错误:错误:无法解析“D:\source\mh\Reclamos-v2\src”中的“@angular/localize”
我应该安装什么?本地化库的名称是什么?
我收到这个奇怪的警告
Locale data for 'en-US' cannot be found. No locale data will be included for this locale
跑步时 ng build --configuration=prod --localize
这是我的 angular.json
// omitted
"i18n": {
"sourceLocale": "en-US",
"locales": {
"sr-Latn": {
"translation": "src/locale/messages.sr.xlf",
"baseHref": "/sr/"
}
}
},
// omitted
Run Code Online (Sandbox Code Playgroud)
该文档明确说明默认情况下导入 en-US。更糟糕的是,当我将 sourceLocale 更改为任何其他语言(比如“de”)时,警告消息就会消失。
手动注册 en-US 区域设置数据也无济于事
升级@angular/core并@angular/material使用ng update命令后,ngcc命令失败并显示以下错误
使用的命令:
ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points
错误:
> Compiling @angular/cdk/stepper : es2015 as esm2015
> Compiling @angular/cdk/drag-drop : es2015 as esm2015
> Error: Error on worker #3: Error: Tried to overwrite node_modules/@angular/cdk/stepper/step-header.d.ts.__ivy_ngcc_bak with an ngcc back up file, which is disallowed.
> at NewEntryPointFileWriter.InPlaceFileWriter.writeFileAndBackup (node_modules/@angular/compiler-cli/ngcc/src/writing/in_place_file_writer.js:37:23)
> at NewEntryPointFileWriter.writeFile (node_modules/@angular/compiler-cli/ngcc/src/writing/new_entry_point_file_writer.js:64:53)
> at node_modules/@angular/compiler-cli/ngcc/src/writing/new_entry_point_file_writer.js:46:69
> at Array.forEach (<anonymous>)
> at NewEntryPointFileWriter.writeBundle (node_modules/@angular/compiler-cli/ngcc/src/writing/new_entry_point_file_writer.js:46:30)
> at ClusterWorker.compile (node_modules/@angular/compiler-cli/ngcc/src/main.js:173:32)
> at Worker.<anonymous> …Run Code Online (Sandbox Code Playgroud) 我最近使用官方 Angular 站点提供的本指南将我的 angular 应用程序从 V8 更新到 V9 。我按照指南中的所有步骤操作,应用程序已成功更新,但现在当我尝试构建时,我收到大量与管道指令甚至我在模板中使用的组件相关的错误。
这是管道错误的一个示例:
无法在 NgModule 中声明“TimeAgoPipe”,因为它不是当前编译的一部分。
指令错误的另一个例子:
无法绑定到“ngModel”,因为它不是“input”的已知属性
这段代码在 Angular 8 上运行良好:
<input required name="password" class="form-control mr-sm-2" type="password" placeholder="Password" [(ngModel)]="model.password"/>
Run Code Online (Sandbox Code Playgroud)
它甚至无法找到我创建的组件,即使它们已在app.module.ts文件中声明。它给了我这个错误:
'app-nav' 不是已知元素:
如果 'app-nav' 是一个 Angular 组件,那么验证它是否是这个模块的一部分。
如果“app-nav”是一个 Web 组件,则将“CUSTOM_ELEMENTS_SCHEMA”添加到该组件的“@NgModule.schemas”以抑制此消息。
这是我的app.module.ts文件,其中包含未找到的所有内容:
<input required name="password" class="form-control mr-sm-2" type="password" placeholder="Password" [(ngModel)]="model.password"/>
Run Code Online (Sandbox Code Playgroud)
Instinct 和https://github.com/AndrewPoyntz/time-ago-pipe/issues/33建议的解决方案有效。你必须记住在 angular.json 上禁用 AOT 编译
我在 Angular 9 应用程序中使用 NGXS 进行状态管理。在状态类之一中,任何依赖项注入都会导致错误“错误:无法解析 TranslationEditorState 的所有参数:(?)”。我尝试过注入服务甚至 HttpClient,但问题仍然存在。事实上,对于任何状态类,我都会遇到相同的错误。难道和app.module中Module注入的顺序有关系吗?
应用程序模块.ts
import { BrowserModule } from '@angular/platform-browser';
import { APP_INITIALIZER, NgModule } from '@angular/core';
import { NgxsModule } from '@ngxs/store';
import { AuthModule } from './auth/auth.module';
import { AppComponent } from './app.component';
import { SharedModule } from './shared/shared.module';
import { AuthInterceptor } from './auth/auth.interceptor';
import { AppRoutingModule } from './app-routing.module';
import { configFactory } from './shared/utils/config.factory';
import { NgxsFormPluginModule } from '@ngxs/form-plugin';
import { NgxsLoggerPluginModule } from '@ngxs/logger-plugin';
import { HTTP_INTERCEPTORS …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个支持多种语言的应用程序——实际上多达 20 种。
默认语言是en-US. 在构建过程中,会创建可以正常工作的翻译版本。
但是,在所有构建中,LOCALE_ID始终是en-US. 所以我不能依赖管道等中的语言环境。它没有使用构建配置中设置的语言环境进行更新。
在编译每个语言环境时,我也收到此警告(此处为德语):
找不到“de-DE”的语言环境数据。此语言环境将不包含任何语言环境数据。
这是构建配置在angular.json中的外观:
"production-de": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb"
}
],
"outputPath": "dist/de",
"baseHref": "/de/",
"i18nLocale": "de-DE",
"i18nFile": "src/locale/messages/messages.de.xlf",
"i18nFormat": "xlf"
},
Run Code Online (Sandbox Code Playgroud)
使用以下命令构建应用程序:
ng build …Run Code Online (Sandbox Code Playgroud) internationalization typescript angular-i18n angular angular9
在 Angular 应用程序中,我通过普通D3或Vega进行 D3 视觉效果。还有 SCSS 样式。
我希望能够从 Javascript 和 SCSS 中引用相同的全局变量以进行样式设置。JSON 文件可以很好地存储我通过简单import语句加载到 Typescript 中的设置。但是如何从 SCSS 做同样的事情呢?
node-sass-json-importer 似乎是一个不错的候选者,但将它添加到 Angular 9 CLI 应用程序对我来说并不明显。
这篇 StackOverflow 帖子不久前谈到了这个话题,但它涉及修改node_modules几乎不可持续的资源。
原始文档中还有一些关于如何在非 Angular 应用程序中调整 webpack 的输入。我不知道如何将其与通过 CLI 构建的 Angular 应用程序相关联。
Webpack / sass-loader Blockquote
网络包 v1
import jsonImporter from 'node-sass-json-importer';
// Webpack config
export default {
module: {
loaders: [{
test: /\.scss$/,
loaders: ["style", "css", "sass"]
}],
},
// Apply the JSON importer via …Run Code Online (Sandbox Code Playgroud) 我有一个独立运行的 angular 应用程序,我正在尝试创建一个电子应用程序,然后mainWindow.loadURL('http://localhost:4200/');它只是:它只是我的开发环境的本地主机,它不是真实的条件。
在电子中,我将 nodeIntegration 设置为 true,这允许我的 angular 应用程序访问 ipc。
const mainWindow = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
}
});
Run Code Online (Sandbox Code Playgroud)
在 angular 我有我的乒乓功能:
public playPingPong() {
if(this._electronService.isElectronApp) {
console.log('Is electron.')
console.log(this._electronService.ipcRenderer);
let pong: any = this._electronService.ipcRenderer.sendSync('ping', 'ping');
console.log(pong);
}
}
Run Code Online (Sandbox Code Playgroud)
尽管在使用标题中的错误记录 ipcRenderer 后,应用程序出错了:
core.js:5845 ERROR Error: Unable to deserialize cloned data due to invalid or unsupported version.
at EventEmitter../lib/renderer/api/ipc-renderer.ts.ipcRenderer.sendSync (ipc-renderer.ts:13)
at ArcMapComponent.playPingPong (arc-map.component.ts:61)
at ArcMapComponent.ngOnInit (arc-map.component.ts:164)
at callHook (core.js:3909)
at callHooks (core.js:3873)
at executeInitAndCheckHooks (core.js:3814)
at refreshView …Run Code Online (Sandbox Code Playgroud) 将 angular 7 更新为 9 后,我在无法读取 null 的属性“fileName”中出现错误。我已将所有依赖项更新到最新版本。
包.json
{
"name": "project name",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "9.0.6",
"@angular/cdk": "^9.1.3",
"@angular/cli": "9.0.6",
"@angular/common": "9.0.6",
"@angular/compiler": "9.0.6",
"@angular/core": "9.0.6",
"@angular/forms": "9.0.6",
"@angular/http": "7.2.16",
"@angular/platform-browser": "9.0.6",
"@angular/platform-browser-dynamic": "9.0.6",
"@angular/router": "9.0.6",
"@ngui/datetime-picker": "^0.16.2",
"angular-flash-message": "^3.4.0",
"angular2-clipboard": "^2.0.14",
"angular2-color-picker": "^1.3.1",
"angular2-cookie": "^1.2.6",
"angular2-flash-messages": "^3.0.1",
"angular2-modal": "^3.0.3",
"angular2-multiselect-dropdown": "^4.6.3",
"chart.js": …Run Code Online (Sandbox Code Playgroud) 我的组件中有一个变量,它在使用时正在更新,console.log(variable)尽管它没有在我的视图中更新{{ variable }},但我已经尝试了几件事,我的最后一个选择是使用Observers,但仍然无法正常工作。
我将解释我的代码:
所以我有一个服务、一个基础组件、一个应用程序组件和另一个组件
我的基本组件没有任何视图。它仅实例化服务。就像这样:
private _communicationService: CommunicationService;
private _clientService: ClientService;
constructor(private injector : Injector) {
this.clientService = this.injector.get(ClientService);
}
Run Code Online (Sandbox Code Playgroud)
(包括获取和设置)
我的应用程序组件和另一个扩展了 BaseComponent
我认为我的实现中的错误是接下来的事情:
我的应用程序组件正在调用window我尝试在 ngInit 上实现的函数
export class AppComponent extends BaseComponent implements OnInit{
constructor(injector : Injector) {
super(injector);
}
ngOnInit(): void {
window.FlashExternalInterface.logLoginStep = (step : string) => {
this.clientService.loadClientProgress(step);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的“其他”组件:
export class LoaderComponent extends BaseComponent implements OnInit {
public progress = 0;
constructor(injector : Injector) { …Run Code Online (Sandbox Code Playgroud) angular9 ×10
angular ×9
typescript ×4
angular-cdk ×1
angular-cli ×1
angular-i18n ×1
angular7 ×1
casting ×1
electron ×1
json ×1
migration ×1
ng-bootstrap ×1
ngxs ×1
sass ×1
view ×1