0

I am using ElementRef to access DOM elements, but I am getting an error,

generic type ElementRef requires 2 type arguments angular 6

This is code

Import

import { Component, OnInit, Input, ElementRef, Renderer2, AfterViewInit, ViewChild, ChangeDetectorRef, OnDestroy  } from '@angular/core';

Code

@ViewChild("transDtls") transModal: ElementRef;

The above code is the syntax I have seen in most sites, I have tried using this way

@ViewChild("transDtls") transModal: ElementRef<HTMLElement, any>;

which I saw in other site, it solved error in IDE, but I`m getting error in console while ng serve

ERROR in src/app/view/menu/transactions/transactions.component.ts(39,41): error TS2707: Generic type 'ElementRef' requires between 0 and 1 type arguments.

Because of this I couldn't use ElementRef, Kindly help I`m new to angular.

Gopesh
  • 3,882
  • 11
  • 37
  • 52
mano10
  • 419
  • 1
  • 5
  • 17
  • Are you getting two errors ? Check where you import `ElementRef` from, be sure to have no duplicates and post the current error. `ElementRef`doesn't need to be typed when used. –  Aug 01 '18 at 07:54
  • I have given import above, there are no duplicates, two different errors based on scenario, which I have described above.. – mano10 Aug 01 '18 at 07:58
  • there shouldn't be any problem try to clear your cache ```npm cache clean --force``` and run again. – Fateme Fazli Aug 01 '18 at 07:59
  • Please use a [mcve] on https://stackblitz.io to reproduce your error –  Aug 01 '18 at 07:59
  • Should I user @ViewChild("transDtls") transModal: ElementRef; or @ViewChild("transDtls") transModal: ElementRef; – mano10 Aug 01 '18 at 08:03
  • Because this gives error while writing in IDE @ViewChild("transDtls") transModal: ElementRef; – mano10 Aug 01 '18 at 08:04
  • Possible duplicate of [Typescript Error: TS2314: Generic type 'ElementRef' requires 2 type argument(s)](https://stackoverflow.com/questions/50704880/typescript-error-ts2314-generic-type-elementreft-any-requires-2-type-argu) – Tim Martens Aug 01 '18 at 08:08

0 Answers0