【发布时间】:2020-09-08 22:05:22
【问题描述】:
鉴于以下 Angular 应用程序,SVG titles 将显示为第一个 HelloComponent 的 rects 的工具提示(悬停时),但不会显示其他的。如果删除 (mousemove) 属性,则会显示所有工具提示。这里发生了什么?如何解决?
https://stackblitz.com/edit/angular-ivy-df8cxp?file=src/app/app.component.ts
import { Component, Input } from "@angular/core";
@Component({
selector: "hello",
template: `
<svg (mousemove)="onMouseMove($event)">
<rect
*ngFor="let item of items"
[attr.x]="item.x"
width="10"
height="100%"
>
<title>{{ item.x }}</title>
</rect>
</svg>
`,
styles: [
`
:host {
display: flex;
}
svg {
flex-grow: 1;
}
`
]
})
export class HelloComponent {
@Input() items: { x: number }[];
onMouseMove(event: MouseEvent) {}
}
import { Component } from "@angular/core";
@Component({
selector: "my-app",
template: `
<hello [items]="items1"></hello>
<hello [items]="items2"></hello>
<hello [items]="getItems3()"></hello>
`
})
export class AppComponent {
items1 = [{ x: 100}, { x: 150 }];
get items2() {
return [{ x: 200}, { x: 250 }];
}
getItems3() {
return [{ x: 300}, { x: 350 }];
}
}
【问题讨论】: