简体   繁体   中英

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

I am trying to recreate the following plunker: https://plnkr.co/edit/RJJdcY?p=preview , but when I have the following code in Angular2, I get the error message "Argument of type 'QueryList<ElementRef>' is not assignable to parameter of type 'string'."

Here is my code as it stands now, does anyone have a suggestion, seeing that I do not know if I am using something that is maybe outdated.

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() {
  }

}

Thanks you very much.

console.debug(this.divs) should be changed to console.log(this.divs)

Thanks to Gunter!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM