我希望能够在我的 Angular 项目中动态加载 CSS。为此,我遵循了本教程中的所有步骤: https://juristr.com/blog/2019/08/dynamically-load-css-angular-cli/
不幸的是,我在下面的 angular.json 中遇到了这个问题:
"dyncss": {
...
"build": {
...
options: {
...
"styles": [
"src/styles.scss",
{
"input": "src/client-a-styles.scss",
"bundleName": "client-a",
"inject": false
},
{
"input": "src/client-b-styles.scss",
"bundleName": "client-b",
"inject": false
}
],
}
},
...
},
Run Code Online (Sandbox Code Playgroud)
当我添加行:“inject”:false时,我在这里收到以下错误:
“架构验证失败,出现以下错误:数据路径“.styles[1]”不应具有其他属性(注入)。数据路径“.styles[1]”应为字符串。数据路径“.styles[1]”应为完全匹配 oneOf 中的一个模式”
如果我删除了"inject": falseng build 行,但我必须注入注入才能随后动态加载 css...
ps:角度版本^9.1.3
请,非常欢迎任何帮助!提前致谢!
我遇到了问题ng serve。当我在我的 Angular 项目上运行它时,大约 10% 的时间,它会在此过程中冻结,并且整个计算机也会冻结。有时它会在一段时间(从20秒到120秒)后解冻并成功编译,有时我需要手动关闭计算机电源。我已经在 2 台计算机上遇到过这个问题。
我注意到的一件事是,当计算机死机时,机箱上 HDD 使用情况的 LED 指示灯会持续闪烁。您知道造成这种冻结的原因是什么吗?这可能是我的项目中的一些错误/错误吗?我ng serve从我的 WebStorm IDE 调用,它已经非常消耗 RAM,那么这可能是 RAM 内存不足的结果吗?我尝试将 ngserve 的输出记录到文件中以防冻结,但它没有显示任何错误。
OS: Ubuntu 20.04.1 LTS || Linux Mint 20
Angular CLI: 10.0.3
Node: 14.14.0
OS: linux x64
Angular: 10.1.6
... common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes
@angular-devkit/architect 0.1000.8
@angular-devkit/build-angular 0.1000.8
@angular-devkit/build-optimizer 0.1000.8
@angular-devkit/build-webpack 0.1000.8
@angular-devkit/core 10.0.3
@angular-devkit/schematics 10.0.3
@angular/cli 10.0.3
@ngtools/webpack 10.0.8
@schematics/angular 10.0.3
@schematics/update 0.1000.3
rxjs 6.6.3
typescript …Run Code Online (Sandbox Code Playgroud) 使用“ng new”创建新项目并修改 tslint.json 以使用制表符而不是空格后,运行“ng lint --fix=true”不会对 .ts 文件产生任何影响:
ng lint --fix=true
Run Code Online (Sandbox Code Playgroud)
仅列出错误,但不修复它们。根据文档,应该如此。
ERROR: 4:1 indent tab indentation expected
ERROR: 5:1 indent tab indentation expected
ERROR: 6:1 indent tab indentation expected
ERROR: 9:1 indent tab indentation expected
Run Code Online (Sandbox Code Playgroud)
环境:Angular CLI:10.1.7
命令是不是错了?
我想与使用Windows 身份验证ng serve(NTLM)保护的后端服务器一起使用。这与这些帖子(示例 1、示例 2 )中的情况几乎相同,只不过服务器是通过HTTPS访问的。
当我尝试使用相同的建议解决方案(适用于 HTTP)时,我收到404错误(但当然可以通过此 URL 访问服务器,我可以直接使用浏览器进行测试)。
const Agent = require("agentkeepalive");
module.exports = {
'/api': {
target: "https://my-server.example.com",
secure: false,
changeOrigin: true,
agent: new Agent({
maxSockets: 100,
keepAlive: true,
maxFreeSockets: 10,
keepAliveMsecs: 100000,
timeout: 6000000,
keepAliveTimeout: 90000
}),
onProxyRes: proxyRes => {
const key = "www-authenticate";
proxyRes.headers[key] = proxyRes.headers[key] &&
proxyRes.headers[key].split(",");
}
}
}
Run Code Online (Sandbox Code Playgroud)
任何帮助,包括一些诊断问题的方法,将不胜感激。
更新:使用 logLevel = "debug" 我得到以下堆栈跟踪(我不明白,因为相同的代理配置在 HTTPS 上运行良好,如果不是 Windows 配置的话):
TypeError [ERR_INVALID_PROTOCOL]: Protocol …Run Code Online (Sandbox Code Playgroud) 我们有一个nrwl-nx工作空间库项目(在 Angular 8 上),在该项目下有 3-4 个Angular库。它的 ng 服务工作正常,ng build my-lib过去也能工作。
然而,在我们的构建代理上,最近我们开始出现以下错误。
C:\pathToProject> my-workspace build:my-lib C:\pathToProject
C:\pathToProject> ng build --project my-lib构建 Angular 包
构建入口点“@my-scope/my-lib”
渲染样式表构建错误
[object Object] 不是 PostCSS 插件
错误:[object Object] 不是
Processor.normalize 处的 PostCSS 插件 (C:\pathToProject\node_modules\ng-packagr\node_modules\postcss\lib\processor.js:145: 15)
在新处理器 (C:\pathToProject\node_modules\ng-packagr\node_modules\postcss\lib\processor.js:51:25) 在 postcss
(C:\pathToProject\node_modules\ng-packagr\node_modules\postcss\lib) \postcss.js:73:10)
在 createPostCssProcessor (C:\pathToProject\node_modules\ng-packagr\lib\ng-v5\entry-point\resources\stylesheet.transform.js:73:12) 在
对象处。(C:\pathToProject\node_modules\ng-packagr\lib\ng-v5\entry-point\resources\stylesheet.transform.js:36:30)
在 Generator.next ()
位于 C:\pathToProject\node_modules\ng- packagr\lib\ng-v5\entry-point\resources\stylesheet.transform.js:7:71
at new Promise ()
at __awaiter (C:\pathToProject\node_modules\ng-packagr\lib\ng-v5\entry-点\资源\stylesheet.transform.js:3:12)
相同的命令在其他机器上运行良好,直到我们清除缓存,重新安装相同的nodejs版本并执行 ng build lib-project 来排除故障。Nodejs v10.16.0、npm v6.9.0。
我尝试过 …
我想在我的 Angular 应用程序中使用 Bootstrap 5 弹出窗口。
这就是我所做的:
我的索引.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>my website</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
<script>
var popover = new bootstrap.Popover(document.querySelector('.popoverable'), {
container: 'body'
})
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
应用程序组件.html
<button type="button" class="btn btn-secondary popoverable" data-container="body" data-toggle="popover" data-placement="bottom" data-content="Bottom popover">
Popover on bottom
</button>
Run Code Online (Sandbox Code Playgroud)
然后在我的页面上,我看到我的样式按钮,但弹出窗口没有出现,并且在控制台中我得到一个Uncaught TypeError: this._element is undefined.
有人能解决我的问题吗?
我将 NX 工作区更新到最新版本 ( "@nrwl/angular": "11.5.2"),将其与 monorepo 中的 Angular 应用程序 (v 11.2.6) 结合使用。
我想使用以下命令生成一个新的 Angular 库:
ng generate @nrwl/angular:library --name=service --style=scss --directory=/libs/booking
Run Code Online (Sandbox Code Playgroud)
但我在控制台中收到以下错误:
SchematicsException [Error]: Project name "-libs-booking-service" is not valid.
New project names must start with a letter, and must contain only alphanumeric
characters or dashes. When adding a dash the segment after the dash must also
start with a letter.
Run Code Online (Sandbox Code Playgroud)
该命令以某种方式在项目名称之前添加了一个破折号-,从而生成错误。
我还清除了node_modules并再次重新安装了软件包,但没有任何运气。
更新
在 Shashank 的提示后,我在下面留下了帮助我解决问题的步骤:
如果我删除目录参数中的前导/,则会收到以下错误:
ng generate @nrwl/angular:library --name=services …Run Code Online (Sandbox Code Playgroud) CREATE firstapp/package.json (1209 bytes)\nCREATE firstapp/README.md (1018 bytes)\nCREATE firstapp/tsconfig.json (783 bytes)\nCREATE firstapp/tslint.json (3185 bytes)\nCREATE firstapp/.editorconfig (274 bytes)\nCREATE firstapp/.gitignore (631 bytes)\nCREATE firstapp/.browserslistrc (703 bytes)\nCREATE firstapp/karma.conf.js (1425 bytes)\nCREATE firstapp/tsconfig.app.json (287 bytes)\nCREATE firstapp/tsconfig.spec.json (333 bytes)\nCREATE firstapp/src/favicon.ico (948 bytes)\nCREATE firstapp/src/index.html (294 bytes)\nCREATE firstapp/src/main.ts (372 bytes)\nCREATE firstapp/src/polyfills.ts (2830 bytes)\nCREATE firstapp/src/styles.css (80 bytes)\nCREATE firstapp/src/test.ts (753 bytes)\nCREATE firstapp/src/assets/.gitkeep (0 bytes)\nCREATE firstapp/src/environments/environment.prod.ts (51 bytes)\nCREATE firstapp/src/environments/environment.ts (662 bytes)\nCREATE firstapp/src/app/app-routing.module.ts (245 bytes)\nCREATE firstapp/src/app/app.module.ts (393 bytes)\nCREATE firstapp/src/app/app.component.html (24955 bytes)\nCREATE firstapp/src/app/app.component.spec.ts (1063 bytes)\nCREATE firstapp/src/app/app.component.ts (212 bytes)\nCREATE firstapp/src/app/app.component.css (0 bytes)\nCREATE firstapp/e2e/protractor.conf.js (904 bytes)\nCREATE firstapp/e2e/tsconfig.json …Run Code Online (Sandbox Code Playgroud) 我已将我的项目更新到最新的角度版本。使用“ ng update”更新后,我收到一条消息,表明所有内容都是最新的。(我的过程的最后一步。所需的包已经更新)
很好,但是当我为项目提供服务时,出现以下错误:
Error: The Angular Compiler requires TypeScript >=4.2.3 and <4.3.0 but 4.3.2 was found instead.
Run Code Online (Sandbox Code Playgroud)
我已经尝试过:npm install typescript@4.3.0但该版本不存在。我宁愿不降级。我努力让我的项目保持最新状态。
我怎样才能解决这个问题。
我正在尝试使用 --serve-path 在该路径下为我的整个应用程序提供服务。例如,我希望我的路径是localhost:4200/foobar我使用的ng serve --serve-path=/foobar/。然后,当我转到该网址时,我的应用程序不会加载,并且出现空白屏幕。
angular-cli ×10
angular ×5
npm ×2
nrwl-nx ×2
bootstrap-5 ×1
css ×1
jasmine ×1
javascript ×1
lint ×1
ng-build ×1
node.js ×1
sass ×1
typescript ×1
webpack ×1
webpack-4 ×1