【发布时间】:2018-02-23 16:52:12
【问题描述】:
我想在名字和姓氏之间添加空格。但是当我运行代码时,它不会增加空间。我也尝试添加选项卡空间,但它没有正确渲染。字符集设置为 utf-8 可以在附加的 html 中看到
export class AppComponent implements OnInit {
firstName: string;
lastName: string;
title: string;
clicked: boolean;
ngOnInit() {
this.firstName = `John`;
this.lastName = `Doe`;
}
printDetails(frstnm: HTMLInputElement, lstnm: HTMLInputElement, event: any): void {
this.firstName = frstnm.value || this.firstName;
this.lastName = lstnm.value || this.lastName;
this.title = `First Name is: ${this.firstName} Last Name is: ${this.lastName}`;
event.preventDefault();
this.clicked = true;
}
isVisible() {
const classes = {
display : this.clicked
}
return classes;
}
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>MyApp</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
</html>
【问题讨论】:
-
Angular 转义 html 实体。答:stackoverflow.com/questions/31548311/angular-2-html-binding
-
如果你这样做
\u00A0会有效吗? -
@loganfsmyth 是的,它确实有效。为什么?
-
@SONGSTER 因为 \u00A0 不是 HTML 实体
-
这是什么?能否请您提供更多详细信息
标签: html angular typescript ecmascript-6