有一种情况在子组件上定义输入,如下所示:
interface MyValues {
text: string;
path: string;
someOtherValue: string;
}
@Input() myValues: MyValues;
Run Code Online (Sandbox Code Playgroud)
我需要myValues通过如下输入从父组件传递给子组件:
<my-child-component [myValues]="myValues" />
Run Code Online (Sandbox Code Playgroud)
由于它不是简单的数据类型输入,因此我无法使用此处Angular 文档中推荐的 i18n 属性样式。这是一个具有多个值的对象,因此在传递给子组件时无法对其进行翻译(除非我遗漏了某些东西)。
在子组件中,有一些代码如下:
<span *ngFor="let myValue of myValues">
<a>{{myValue.Text}}</a>
</span>
Run Code Online (Sandbox Code Playgroud)
通常我想做的是为需要翻译的锚点分配一个 id,如下所示:
<a i18n="@@myChildComponent_text">{{myValue.Text}}</a>
Run Code Online (Sandbox Code Playgroud)
这样做的问题是它会在名为的翻译文件中创建一个字段,@@myChildComponent_text以进行翻译。但是,传递给这个子组件的这个对象在里面的值是动态的myValues,因此字面翻译将根据传入的内容而变化。
我的问题是,在将对象传递给子组件上的输入时,我如何仍然利用i18nAngular 国际化能力和@@id自定义 id,该对象将在其中具有需要转换的不同物理值?
我当前的角度版本是“^7.1.4”,我想继续使用相同的版本。但是在做 ng serve 时,我遇到了错误。
您正在运行 Node.js 的 v8.9.3 版本,Angular CLI 8.0+ 不支持该版本。支持的官方 Node.js 版本是 10.9 或更高版本。
请访问https://nodejs.org/en/以查找有关如何更新 Node.js 的说明。
节点版本:v8.9.3 NPM 版本:6.4.1
提前致谢
我有一个 Angular CLI 库,其中每个组件只能通过它们各自的入口点(如 Angular Material)导入:
import {Foo} from '@myLib/foo
import {Bar} from '@myLib/bar
Run Code Online (Sandbox Code Playgroud)
所以我不想要 ng-packagr 配置中的主要入口点。
我已经定义了所有次要入口点,我想删除主要入口点,因此用户不能只是“从 '@myLib ”导入 {Bar},但是 ng-package.json 需要一个 entryFile,当我离开 entryFile 时空我收到一个错误
错误:内部错误:无法获取入口点的符号
我必须在 entryFile 中添加至少一个有效的导出。
Angular Material 团队似乎已经做到了这一点 - https://github.com/angular/components/blob/master/src/material/index.ts
关于如何做到这一点的任何想法?
在我们的 Angular 应用程序中,我们使用 Angular i18n 机制在组件 HTML 中将字符串标记为可翻译,并ng xi18n用于提取可翻译字符串并将它们写入 xlf 文件。但是除了我们的应用程序字符串之外,xlf 文件还包含来自 ng-bootstrap 库的字符串,我们在我们的应用程序中使用了它,并且它的所有代码都在 node_modules 文件夹中。
下面的 xml 块是一个示例,它显示了一个字符串,我们不希望在我们的 messages.xlf 中有,但它也被ng xi18n工具提取:
...
<trans-unit id="ngb.alert.close" datatype="html">
<source>Close</source>
<context-group purpose="location">
<context context-type="sourcefile">node_modules/@ng-bootstrap/ng-bootstrap/alert/alert.d.ts</context>
<context context-type="linenumber">3</context>
</context-group>
</trans-unit>
...
Run Code Online (Sandbox Code Playgroud)
有没有办法在提取的字符串中不包含来自 node_modules 的内容?像一些可以在某个地方配置的排除选项?我在 google 上找不到任何类似的东西,但我想在打开 angular-cli github 项目上的错误请求之前先在这里问一下......
更多细节:
通过以下步骤给出了重现此问题的简单方法:
@ng-bootstrap/ng-bootstrap": "^5.2.1"将这一行添加到 package.json 并运行 npm install<div i18n>example text</div>我是这个平台的新手。
我安装了Node.js但是当我尝试运行命令npm install -g @angular/cli 时
我收到了这个错误:
**npm WARN deprecated mkdirp@0.5.3: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN rollback Rolling back @schematics/angular@9.0.6 failed (this is probably harmless): EPERM: operation not permitted, lstat 'C:\Users\Vivek\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\@sche**
Run Code Online (Sandbox Code Playgroud)
此外,当我尝试运行版本命令时
它向我展示了
**C:\Users\Vivek>ng v
internal/modules/cjs/loader.js:985
throw err;
^
Error: Cannot find module 'C:\Users\Vivek\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng'**
Run Code Online (Sandbox Code Playgroud) 我是角度的初学者,我正在使用角度材质对话框。首先,我将材料添加到我的项目中并从@angular/material.
当我在中添加 ( import { MatDialogModule } from '@angular/material/dialog';)) 时app.module.ts,在编译项目时出现以下错误
ERROR in node_modules/@angular/cdk/coercion/array.d.ts(10,60): error
TS1005: ',' expected.
node_modules/@angular/cdk/coercion/array.d.ts(10,61): error TS1005:
',' expected. node_modules/@angular/cdk/coercion/array.d.ts(10,75):
error TS1144: '{' or ';' expected.
node_modules/@angular/cdk/coercion/array.d.ts(10,77): error TS1011: An
element access expression should take an argument.
Run Code Online (Sandbox Code Playgroud)
为什么?
这是我的 package.json:
{
"name": "sales-maret",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^7.2.16",
"@angular/cdk": …Run Code Online (Sandbox Code Playgroud) 您好 在 Angular 8 中创建了一个项目。最初它只支持一种默认语言(US-EN)。然后我应用了本地化。
在准备生产构建的本地化之前,我曾经给出以下命令。
ng build --prod --base-href "/Windchill/com/qiwkCollaborator/"
Run Code Online (Sandbox Code Playgroud)
本地化后,我在 angular.json 和 package.json 中做了一些更改。在进行这些更改后,每当我发出任何准备构建它的命令时,都会出现以下错误。
An unhandled exception occurred: Configuration 'production' is not set in the workspace.
Run Code Online (Sandbox Code Playgroud)
Package.json 文件的某些部分如下:
"name": "qwik-collaborator",
"version": "1.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"build-locale:en": "ng build --prod --i18n-locale en --i18n-format xlf --i18n-file src/translate/messages.en.xlf --output-path=dist/en --baseHref /en/",
"build-locale:fr": "ng build --prod --i18n-locale fr --i18n-format xlf --i18n-file src/translate/messages.fr.xlf --output-path=dist/fr --baseHref /fr/"
Run Code Online (Sandbox Code Playgroud)
Angular.json …
当我这样做时ng serve,日志会显示如下错误:
Error from chokidar (/PATH_OF_MY_PROJECT/node_modules/ionicons/dist/ionicons/svg): Error: ENOSPC: System limit for number of file watchers reached, watch '/PATH_OF_MY_PROJECT/node_modules/ionicons/dist/ionicons/svg/ios-subway.svg'
Run Code Online (Sandbox Code Playgroud)
我读到解决方案是在 Linux 上更改观察者文件,但这是一个糟糕的解决方案!
为什么 Angular 需要看到对 的更改node_modules?这是一个不会改变的文件夹。如果我需要安装一个新库,我可以重新启动服务器。
如果您的解决方案是:请不要回答我
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf。我不想使用这个糟糕的解决方案。
我们的应用程序使用 node.js Core & Angular 7.2 版
我们经常推出 Angular 应用程序的生产版本,以便在一个月内部署 3-4 次更改。
我收到了一些客户的投诉,他们无法看到更改,除非他们清除缓存或在浏览器中硬重新加载页面。
我认为ng build --prod创建了唯一的哈希值,以便处理缓存破坏,但似乎没有发生。
在angular.json我有以下用于生产构建的配置
"production": {
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": false,
"vendorChunk": false,
"buildOptimizer": true,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
]
}
Run Code Online (Sandbox Code Playgroud)
运行后ng build --prod它会生成散列文件,它与基于更改的先前版本不同。此外,我已将服务器配置为不缓存index.html. 那么为什么有时用户需要硬重新加载页面或手动清除缓存以获取最新更改?
除了告诉客户清除他们的缓存之外,我还有什么办法可以解决这个问题?
任何建议将不胜感激。
我有一个 angular 9 应用程序,我在其中从资产文件夹中读取了 api url:
@Injectable()
export class ConfigService {
private configUrl = '../../../assets/config/config.json';
constructor(private loggerService: LoggerService) { }
public async loadConfig(): Promise<any> {
try {
const response = await fetch(this.configUrl);
if (!response.ok) {
throw new Error(response.statusText);
}
return await response.json();
} catch (err) {
this.loggerService.error(`ConfigService 'loadConfig' threw an error on calling ${this.configUrl} : ${err.tostring()}`);
}
}
}
Run Code Online (Sandbox Code Playgroud)
用于读取配置文件的方法在构建后配置角度生产文件中描述。
environment.ts 是
export const environment = {
production: false,
apiUrl: "https://localhost/api/",
};
Run Code Online (Sandbox Code Playgroud)
environment.prod.ts 是
export const environment = …Run Code Online (Sandbox Code Playgroud) angular-cli ×10
angular ×9
angular-i18n ×2
angular9 ×2
angular8 ×1
caching ×1
chokidar ×1
dialog ×1
ng-packagr ×1
node.js ×1
npm ×1
typescript ×1
watch ×1