Javascript scrollIntoView()不';不能使用应用程序选择器

Javascript scrollIntoView()不';不能使用应用程序选择器,javascript,angular,typescript,Javascript,Angular,Typescript,有人知道滚动定位的正确实现吗。这种方法不起作用: 以下是引用其他组件的模板: <app-app1 id="id1"></app-app1> <app-app2 id="id2"></app-app2> <app-app3 id="id3" *ngIf="test"></app-app3> scrollIntoView()已执行,但它滚动到了错误的位置(如本节的中间部分),对于app-app3根本不起作用。我这样修复了它:

有人知道滚动定位的正确实现吗。这种方法不起作用:

以下是引用其他组件的模板:

<app-app1 id="id1"></app-app1>
<app-app2 id="id2"></app-app2>
<app-app3 id="id3" *ngIf="test"></app-app3>
scrollIntoView()已执行,但它滚动到了错误的位置(如本节的中间部分),对于app-app3根本不起作用。

我这样修复了它: 1.从应用程序选择器组件中删除“id3”:

致:


单击按钮前后的
test
是否为真?在我的情况下,页面加载时为真。。而且没有改变*如果没什么大问题。。首先,我希望它滚动到应用程序中的正确位置selector@JohnGlabb是否有多个元素的
id
id1
。否。。这是独一无二的。。考虑每个组件的内容非常大。我甚至试着把它包装成父母的
let elm = document.querySelector("#id1");
if (elm)
  elm.scrollIntoView();
   change: <app-app3 id="id3" *ngIf="test"></app-app3>
   to:     <app-app3 *ngIf="test"></app-app3>
let elm = document.querySelector("#id3");
if (elm)
  elm.scrollIntoView();
let elm = document.getElementById("id3");
elm.scrollIntoView({behavior: "instant", block: "center", inline: "center"});