0

我尝试使用 SVG 和 Angular。

谁能告诉我为什么这不适用于 ChildView 但适用于 getDocumentById?

import { Component, ViewChild } from '@angular/core';

@Component({
  selector: 'a',
  template: `
<svg height="600px" width="600px" [attr.viewBox]="vb">
  <g stroke="black" fill="none" stroke-width="1">
    <path id="ppp" #ppp d="M10 10 H 90 V 90 H 10 L 10 10"/>
  </g>
  <circle id="stroke-point" [attr.cx]="px" [attr.cy]="py" r="2" fill="red" />
</svg>

<input type="button" (click)="foo ()" value ="click me!"/>
`
})
export class A
{
  @ViewChild ("ppp") pcv;

  px : number = 20;
  py : number = 40;

  foo ()
  {
    console.log (this.pcv.isPointInFill (new DOMPoint (this.px, this.py));                            // error, why??
    console.log (document.getElementById ('ppp').isPointInFill (new DOMPoint (this.px, this.py));     // ok!
  }
}
4

0 回答 0