默认情况下,Angular 6以上将应用程序的angularCompilerOption:preserveWhitespaces设置为false。就会导致元素之间没有间距。
解决办法如下
目前,在JIT模式下,我们可以将其设置为 CompileOptions : main.ts
platformBrowserDynamic().bootstrapModule(AppModule, { preserveWhitespaces: true });
1
对于aot,我们必须将此选项添加到 tsconfig.app.json
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"baseUrl": "./",
"module": "es2015",
"types": []
},
"exclude": [
"test.ts",
"**/*.spec.ts"
],
"angularCompilerOptions": {
"preserveWhitespaces": true
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16