gpt4 book ai didi

angular-cli - Angular CLI (ng) 使用单引号而不是双引号

转载 作者:行者123 更新时间:2023-12-04 04:02:38 25 4
gpt4 key购买 nike

当我使用 'ng generate' 命令时,它使用路径的引号编写我的导入语句。我希望它改为使用单引号。是否可以以某种方式配置它?

最佳答案

您目前(从 7.1 开始)无法配置 Angular 以生成带有您选择的引号的组件和其他实体。它目前使用单引号。如果您对此不满意,您可以告诉它自动运行 tslint 并在生成后自动修复所有问题。

首先,确保您有在 tslint.json 中强制使用双引号的规则。 :

"quotemark": [true, "double"],

接下来,在您的 angular.json在原理图部分(在根级别),您可以提供选项 lintFix它告诉 angular 根据您的 tslint 配置自动修复生成的文件:
"schematics": {
"@schematics/angular:component": {
"prefix": "app",
"styleext": "scss",
"lintFix": true
},
"@schematics/angular:directive": {
"prefix": "app",
"lintFix": true
},
"@schematics/angular:pipe": {
"lintFix": true
},
"@schematics/angular:class": {
"lintFix": true
},
"@schematics/angular:module": {
"lintFix": true
},
"@schematics/angular:service": {
"lintFix": true
}
}

这应该在 linux 上运行良好,但在 Windows 上,目前有 bug , 生成时使用了错误的文件路径。在修复之前,您不能直接在您的 components 中生成组件。目录,但您更需要在项目根目录中生成它,并在命令路径中指定它应该生成的目录:
ng g component components/my-component my-component

关于angular-cli - Angular CLI (ng) 使用单引号而不是双引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43108928/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com