Questions tagged [viewchild]

ViewChild is a decorator for Angular component variables, which allow to bind a template element.

ViewChild is a decorator for Angular component variables, which allow to bind a template element. Official Angular documentation here: https://angular.io/api/core/ViewChild.

437 questions
0
votes
0 answers

Ionic 3 ViewChild undefined on subscribe

I have a component and a ViewChild to get its instance, but when I'm trying to load, it returns undefined. Here is my code @ViewChild('mapComponent') mapComponent : MapComponent; async ionViewWillEnter() { this.userInfo = await…
Joan
  • 233
  • 1
  • 5
  • 17
0
votes
1 answer

Why do we need to use @ViewChild to call function of a component from other component?

My tutor told me that, "In angular we can use function defined in any service by just importing that service but we can't import a component in any other component. To use function defined in any other component we need to use…
0
votes
1 answer

calling template name via input

let's say i have several variations of btn-groups in a component and want to group these as templates. in the parent element i want to call these templates by injecting the string (template name). that's what i've…
kingmauri
  • 345
  • 1
  • 3
  • 9
0
votes
1 answer

Why ViewChild doesn't work with attr.id in angular8+?

ViewChild works when I specify id like
test
But when I do:
test
I get something like:
test
in output html, but with an error in the same…
mr_blond
  • 1,586
  • 2
  • 20
  • 52
0
votes
1 answer

Angular How to fix error in @ViewChild Expected 2 arguments, but got 1.ts (2554)?

Angular @ViewChild Error: Expected 2 arguments, but got 1. ts (2554). i am a new learner and right now i am stuck at a point where i dont understand why am i getting this error to my export class @ViewChild('namInput') this line of code is then…
khan
  • 1
  • 1
0
votes
0 answers

Access an Angular ng-template within the same component as TemplateRef

I'm currently writing my own logic for leaflet and need a way to load ng-templates in the same component to display icons on the map. My current state looks like this (unfortunately nothing is displayed on the map). My template:
Codehan25
  • 2,704
  • 10
  • 47
  • 94
0
votes
1 answer

Declare View child conditionally

I have input box inside two divs that render conditionally. html
.ts @ViewChild('ref ') ref : ElementRef; ngOnInit(){ if(someCondition){ show = true; …
Md. Parvez Alam
  • 4,326
  • 5
  • 48
  • 108
0
votes
0 answers

angular 8 @ViewChild returns undefined

I'm trying to use angular 8 @ViewChild to variables from one component to another but it is producing undefined import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-signin', templateUrl: './signin.component.html', …
0
votes
0 answers

Adding css classes dynamically to viewChild element

I want to add a class on blur to a child element of , which of course is not present in the html because it's compiled. The child element is this one : .ng-select > .ng-select-container .ng-has-value I have tried : In CSS file : …
A G
  • 86
  • 11
0
votes
0 answers

angular - how do I use @Input string for selector?

I want use '@Input()' string for selector, but I can't, the selector always log undefined, here my examples: Specific example /********* compA File *********/ // compA -> html (call compB 3 times, every time keying in the different string in…
Pork Jackson
  • 339
  • 1
  • 15
0
votes
1 answer

Can't pass data from Child to Parent using @ViewChild Angular 7

Hi I can't pass my data from child to parent using @ViewChild I have this code from admin-layout.component.ts @ViewChild(TribeComponent)  getRoute :TribeComponent; ngAfterViewInit() { console.log( this.getRoute); this.message =…
Mark
  • 293
  • 1
  • 11
  • 25
0
votes
1 answer

How to access child components properties and methods in single variable?

I have one parent component and multiple child components. ... In order to communicate between parent child either I can make use of event decorators (@Input/@Output). Alternately I can…
shreyansh
  • 1,637
  • 4
  • 26
  • 46
0
votes
2 answers

Expected 2 arguments, but got 1.ts(2554) core.d.ts(8054, 47): An argument for 'opts' was not provided

This is a part of my code that I get this error: Expected 2 arguments, but got 1.ts(2554) core.d.ts(8054, 47): An argument for 'opts' was not provided. from here: import {ViewChild, ChangeDetectorRef, AfterViewInit} from "@angular/core"; import…
Hasani
  • 3,543
  • 14
  • 65
  • 125
0
votes
1 answer

wrong expected arguments of @ViewChild and ngAfterViewInit doesn't work

I am following the guidance However, the @ViewChild and ngAfterViewInit do not work for me. The error information is like this. It said I miss one argument. And I have tried to add 2 arguments like this, but it still does not work. And the…
hyzheng
  • 11
  • 4
0
votes
1 answer

Can't access value from child component : Undefined - Angular 7

I want to pass a value betwen components in order to switch from a list of candidates to another panel where i can edit the selected candidate. Sadly, i get this error : ERROR TypeError: "this.listCandidateComponent is undefined" in my…
Triss
  • 23
  • 4