By default Angular strips all whitespaces in templates to save bytes. Generally it’s safe.
For rare cases when you need to preserve spaces you can use special ngPreserveWhitespaces
attribute:
<div ngPreserveWhitespaces>
(___()'`;
/, /`
jgs \\"--\\
</div>
You can also use preserveWhitespaces option on a component.
file:app.component.ts
import { Component } from '@angular/core';
@Component({
preserveWhitespaces: false,
selector: 'my-app',
template: `
<h1> Look at mee in dev tools! :( </h1>
<div>
__
(___()'';
/, /
jgs \\"--\\
</div>
<h1> Now look at me, I'm cute!! </h1>
<div ngPreserveWhitespaces>
__
(___()'';
/, /
jgs \\"--\\
</div>
`
})
export class AppComponent {}
翻译自:https://www.30secondsofcode.org/angular/s/preseving-whitespaces