问题标签 [angular12]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
angular - 意外令牌:升级到 Angular12 后的 punc (:) [mathjax/es5/sre/mathmaps/de.js:2,19]
我已将我的 Angular 应用程序升级到版本 12。除 mathjax 外,一切正常。运行时ng serve
我收到以下错误
SyntaxError: Unexpected token: punc ())等几个问题表明包文件中存在无效字符。下面是 mathjax/es5/sre/mathmaps/de.js:2,19
如何解决此错误?更改文件可能不是一个可行的解决方案,因为发生此错误的 6 个不同文件中有大约 130 行。
该构建已在 Angular 11 中成功运行
下面是我的eslint
配置文件
angular - Angular 12 将 json 导入 ts
我有一个src/assets/version.json
包含以下内容的 json 文件:
我将文件导入到*.ts
,例如:
输出
这适用于 Angular 11,但在 Angular 12 上,CLI 显示错误
这是我的 tsconfig.base.json
如何修复此错误?
angular - 如何将外部样式表用于 Angular 材质颜色
TL; DR:如何将 Angular 材质 12 颜色变量存储在单独的文件中(@import 和 @use 不起作用)?
使用 Angular 11 时,我可以有一个 variables.scss 文件来存储角度材质颜色,然后在 styles.scss 中使用 @import 来使用这些样式: variables.scss:
样式.scss:
但是,当我更新到 angular 12 时,东西发生了变化,因此之前导入变量的方法会引发错误:
样式.scss:
变量.scss:
事实证明,为了抑制该错误,您必须使用“@use”而不是“@import”:styles.scss:
但是,我得到了一个错误:
然后我尝试了:styles.scss:
但后来我得到了这个错误:
那么,我如何将这些颜色存储在一个单独的文件中而不会出错?
angular - Angular Observable 返回订阅者而不是 JSON 并且字符串显示未定义且没有结果
我在 as 中定义的ngOnInitapp.component.ts
函数。
这是我的api.service.ts
。
只有这个显示undefined两次await this.api.GetSwapi2().subscribe(j => console.log(j));
其他人看不到console.log
我只是想在我的app.component.ts
.
webpack-5 - 升级到 Angular 12 后,应用程序抛出运行时错误“Uncaught TypeError: i is not a function”
最近我将 Angular 应用程序升级到 12 版本,ng serve 和 ng build 工作正常。
将代码移动到 prod 后,出现如下运行时错误,很难找出根本原因
angular - ng 服务“无法获取 /”
升级到 Angular 12 后,我无法在 localhost:4200 上为开发服务器提供服务。
如果我运行,只有一个错误ng serve
:
ng build
没有错误并生成一个工作应用程序。
禁用常春藤没有帮助。
我的 angular.json:
浏览器说:404 localhost:4200
看起来服务器没有运行。
删除文件夹 /node_modules 并运行npm install
change nothing。
我能做些什么?任何想法?
[编辑]
操作系统:Ubuntu 20.04
ng v
:
该应用程序是使用 CLI 创建的。
我的应用程序从 11 升级到 12,请参阅update.angular.io。
angular12 - 编译.errors.push(新的 webpack_1.WebpackError(消息))
升级到 Angular12 后,遇到了类似的问题 compiler.errors.push(new webpack_1.WebpackError(message)); 在 node_modules@ngtools\webpack\src\webpack-diagnostics.js:17 TypeError: webpack_1.WebpackError is not a constructor at Object.addError (\node_modules@ngtools\webpack\src\webpack-diagnostics.js:17:29))在 \node_modules@ngtools\webpack\src\ivy\diagnostics.js:19:39 在 AngularWebpackPlugin.updateAotProgram(\node_modules@ngtools\webpack\src\ivy\plugin.js:342:17)
angular - 无法让 ColorThief 在 Angular 中正常工作,找不到库方法?
我正在尝试在 Angular 12 项目中使用 Library ColorThief(https://lokeshdhakar.com/projects/color-thief/),但没有成功让它工作。我从做开始$ npm i --save colorthief
,然后在我想要的组件 .ts 文件中:
const ColorThief = require('colorthief');
.
一切都正确编译,但某些方法在浏览器中触发时无法识别。
我也尝试将脚本标签添加到我的 index.html 文件中,但没有成功。
我的组件 TS 文件:
有人知道我做错了什么吗?或者在 Angular 中成功使用 ColorThief 的人?
css - Z-index 在 CSS 中包含 #
我最近从 angular 10 更新到 12。
我使用 SCSS。
更新后,我注意到我的徽标位于内容后面,并且我所有的 z-index 值都在值前加上了 # ,我不知道原因,也找不到任何关于此更改源自何处或什么是的好信息原因。
除了包的 src package.json 更新之外,我的配置文件或构建管道没有任何变化
我还使用角度材料作为我的 UI 组件库,并另外导入了引导间距模块
我知道 CSS 无效。(构建后)。它在设计时有效,但在运行时构建后,无论出于何种原因,它都会在前面加上标签。
更新前并非如此
这是设计时间
这是我在这里缺少的一些新的角度特征吗?在文档中找不到任何相关内容。
这和艾薇有关吗?
编辑:
我相信这可能与最近从 @import 到 @use 语句的 sass API 更改有关。ng update
命令应该(根据文档)为我更新和重构 scss,但事实并非如此。
一旦我完成重构,如果它解决了问题,我会在这里发布它作为答案