我正在寻找一种方法让一个 node_modules 文件夹在我的不同项目中使用。我找到了pnpm,安装了它,并使用以下命令创建了一个项目:
ng new test-pnpm --skip-install
ng config cli.packageManager pnpm
pnpm install
ng serve
Run Code Online (Sandbox Code Playgroud)
这个项目没有启动。当我删除这个项目 和 时.pnpm-stor folder,我无法为下一个项目安装包pnpm。
谁能告诉我在项目中使用的步骤,如何配置,如何安装,如何添加包,以及如何在不同的项目中使用?
如果我从类递归调用方法,是否可以在单独的文件中创建树/递归对象并避免Circular dependency detected使用Angular CLI发出警告?
(在 angular 7 中测试)我知道这是依赖注入(文章)中的一个问题,但是作为构造函数用于来自外部 api 的数据或用于内部目的的对象呢?如果无论如何这都不是一个好主意,你如何解决它?(我想这个“子问题”的答案是模型的变化,那么我应该如何修改我的模型?)我寻找解决方案,但最接近的问题并没有帮助我将相同的方法应用于我的情况。
我有Emails和Attachments(带有附件的电子邮件 - 带有附件的整个电子邮件Email也可以是附件,Attachment是具有属性的分隔对象,内容可以是File或Email,但在这里,为简单起见,假设附件始终为 1Email或 null)。
每个类都有用于从 JSON 对象创建实例的静态方法(我从 API 获取 JSON,然后我将通过调用fromJson顶级对象上的静态方法来创建表示 API 值的对象实例):
文件:app/model/email.ts(部分代码)
import { Attachment } from './attachment';
export class Email {
// some attributes
public attachment?: Attachment;
public static fromJson(js: JSON): Email {
const e = new Email(); …Run Code Online (Sandbox Code Playgroud) 我们的应用程序是使用 angular-cli(版本:7.0.2)和 angular(版本:7.0.0)开发的。我们的图像文件很少,pdf 保存在资产文件夹中。每 3 个月发布一次应用程序的每个版本,这些文件都会发生变化。
我通读了此链接中提到的各种技术:使用同一网址中的新图片刷新图片
不确定哪个是最好的解决方案。任何关于如何实现缓存破坏的建议/代码片段表示赞赏。
我有一个 angular 6 应用程序,我正在使用 karma + jasmine 来运行我的测试。但是当我运行时,ng test我收到以下错误:
错误 TS2688 中的错误:找不到“jest”的类型定义文件。
有谁知道如何解决这个问题?
我创建了一个 angular 库项目,我想在其中使用 SCSS 作为样式。
所以我已经配置
ng config schematics.@schematics/angular:component.styleext scss
Run Code Online (Sandbox Code Playgroud)
这对angular.json文件做了一个条目
"schematics": {
"@schematics/angular:component": {
"styleext": "scss"
}
}
Run Code Online (Sandbox Code Playgroud)
现在我在我的库组件中使用materialize-css UI 库。它需要导入它的 SCSS 文件。
我看不到style.scss文件,我可以在其中导入此文件以及我的组件和其他常见样式?
我尝试创建一个并进入angular.json
"styles": ["projects/library_name/styles.scss"]
Run Code Online (Sandbox Code Playgroud)
下projects-> library_name-> architect-> build->options
但这在构建库项目时显示错误
Schema validation failed with the following errors:
Data path "" should NOT have additional properties(styles).
Run Code Online (Sandbox Code Playgroud)
更新
我得到了这个,如果有帮助,解决同样的问题!
现在可以使用 来获得非平面的项目结构ng build,而不是这样:
index.html
main.bundle.js
styles.bundle.js
...
Run Code Online (Sandbox Code Playgroud)
我希望脚本位于子文件夹中
index.html
scripts/main.bundle.js
scripts/styles.bundle.js
...
Run Code Online (Sandbox Code Playgroud)
我找到了一个关于此的主题:“ng build”将脚本移动到子文件夹但租用解决方案是eject从cli进入项目webpack但Angular 7此不再可用,ng eject现在已禁用:
'eject' 命令已被禁用,将在 8.0 中完全删除。新的配置格式提供了更大的灵活性,无需弹出即可修改工作区的配置。
有几个项目可以与新的配置格式结合使用,提供弹出的好处而无需维护开销。一个这样的项目是 ngx-build-plus 在这里找到:https : //github.com/manfredsteyer/ngx-build-plus
Angular 提供的angular.json文件租用文档非常差https://github.com/angular/angular-cli/wiki/angular-workspace因此很难在实际项目问题中使用此配置文件。
我想以纯文本格式或 HTML 格式呈现基本的客户信函,以便客户可以在 TextArea 或 HTML 编辑器中进一步编辑。我正在考虑使用 Handlebars.js 来呈现带有小胡子标签的 HTML 模板以及包含各种业务信息的 JSON 对象。
我做过:
import * as Handlebars from 'handlebars';
...
const template = Handlebars.compile(this.exampleHtmlTemplate);
this.note = template({ title: 'My title', body: 'My body' });
Run Code Online (Sandbox Code Playgroud)
使用 Angular Cli 编译时,出现以下错误:
chunk {vendor} vendor.js, vendor.js.map (vendor) 7.84 MB [initial] [rendered]
WARNING in ./node_modules/handlebars/lib/index.js 22:38-56
require.extensions is not supported by webpack. Use a loader instead.
WARNING in ./node_modules/handlebars/lib/index.js 23:2-20
require.extensions is not supported by webpack. Use a loader instead.
WARNING in ./node_modules/handlebars/lib/index.js 24:2-20 …Run Code Online (Sandbox Code Playgroud) 我正在尝试从库中延迟加载 NgModule。我有一个 ng 应用程序,其中包含一些库(项目)。这个库在其他一些项目中被重用。问题是我找不到解决方案,它适用于 jit 和 aot,以及编译/未编译库。
文件结构是这样的
app
-projects
--lib
---(lib files)
-src
--(app files)
Run Code Online (Sandbox Code Playgroud)
AppModule 有路由,看起来像这样
const routes: Routes = [
{
path: 'eager',
children: [
{
path: '',
component: LibComponent // component imported from lib
},
{
path: 'lazy',
loadChildren: 'lib/src/lib/lazy/lazy.module#LazyModule' // module i want to load lazily
}
]
}
];
Run Code Online (Sandbox Code Playgroud)
如果我像这样使用它,则在尝试导航到 jit 中的惰性路由时会出现运行时错误(aot 工作正常):
ERROR Error: Uncaught (in promise): TypeError: undefined is not a function TypeError: undefined is not a function
此评论https://github.com/angular/angular-cli/issues/9488#issuecomment-370065452建议不要将 LazyModule …
@angular 常春藤问题
当我使用 ng cli 时,它将模块编译为 esm2015,我的问题是我有一个旧系统,因为 angular 2 次,我使用 webpack,但对我来说它编译为 es5。
如何更改它以编译为 esm2015?
我的 tsconfig.aot.json:
{
"compilerOptions": {
"rootDir": ".",
"baseUrl": ".",
"skipLibCheck": true,
"outDir": "build/aot",
"target": "es2015",
"module": "esnext",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"lib": [
"es2018",
"dom"
],
"paths": {
"corifeus-web-material": [
"build-modules/corifeus-web-material/index.ts"
],
"corifeus-web": [
"build-modules/corifeus-web/index.ts"
],
"corifeus-web-material/*": [
"build-modules/corifeus-web-material/*"
],
"corifeus-web/*": [
"build-modules/corifeus-web/*"
]
}
},
"include": [
"build-modules/**/*",
"src/angular/**/*",
"test/angular-webpack/**/*"
],
"exclude": [
"src-save",
"*.worker.js", …Run Code Online (Sandbox Code Playgroud) 我有一个在 python 服务器上运行的 angular 7 应用程序,我们正在使用 angular-cli 构建项目文件。在构建时,我正在使用以下命令设置缓存突发选项。
ng build --prod --build-optimizer --aot --output-hashing=all
output-hashing=all 将根据角度文档处理缓存突发。虽然我提供了这个标志,但在部署我们的应用程序文件名后附加了哈希值(styles.a5169d3732258e921e2c.css、main.8dc0644c88c4fbf67797.js)但 index.html 文件总是显示缓存版本。
我想在客户端缓存除 index.html 之外的所有文件。我将如何做到这一点?
angular-cli ×10
angular ×8
angular7 ×3
angular6 ×2
typescript ×2
jasmine ×1
javascript ×1
jit ×1
karma-runner ×1
lazy-loading ×1
mustache ×1
pnpm ×1
sass ×1
webpack ×1