簡體   English   中英

Angular2 - 類型&#39;QueryList的參數 <ElementRef> &#39;不能賦值給&#39;string&#39;類型的參數

[英]Angular2 - Argument of type 'QueryList<ElementRef>' is not assignable to parameter of type 'string'

我正在嘗試重新創建以下plunker: https ://plnkr.co/edit/RJJdcY p = preview,但是當我在Angular2中有以下代碼時,我收到錯誤消息“類型的參數'QueryList <ElementRef>'不能分配給'string'類型的參數。“

這是我現在的代碼,有沒有人有一個建議,看到我不知道我是否正在使用可能過時的東西。

import { OnInit, ViewChild, ViewChildren, Component, QueryList, ElementRef } from '@angular/core';

@Component({
  selector: 'nlr-container-test-container',
  template: `
  <h2>Hello</h2>
  <input #myname (input)="updateName(myname.value)" value="John Doe">

  <div #div1></div>
  <div #div2></div>
  <div #div3></div>

`,
  styleUrls: ['./container-test-container.component.css']
})
export class ContainerTestContainerComponent implements OnInit {

  constructor() { }

  @ViewChild('myname') input:ElementRef; 

  @ViewChildren('div1,div2,div3') divs: QueryList<ElementRef>;

  //@ViewChildren('.plates', {read: ElementRef}) 
  //public books: QueryList<ElementRef>

  ngAfterViewInit() {
    console.log(this.input.nativeElement.value);
    console.debug(this.divs);
  }

  ngOnInit() {
  }

}

非常感謝你。

console.debug(this.divs)應該更改為console.log(this.divs)

感謝Gunter!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM