456 questions
0
votes
1
answer
22
views
Cant change Angular Materials paginator value after using viewChild signal
I need to change my tables paginators pageIndex and pageSize, my code works well when i use ViewChild, but i want to use signal query, when i use signal query i got this error;
Writing to signals is ...
1
vote
1
answer
43
views
in Angular Signals, can you use viewChild() + effect() to handle changes to a child element?
Let's say I want to know when a particular child element in my component is scrolled. Suppose I declare:
contentPanel = viewChild.required<ElementRef>('contentPanel');
contentScrollTop = ...
1
vote
1
answer
30
views
How to check if the passed reference is an instance of a particular ViewChild Reference in Angular
I have a viewchild ref in my .ts file like,
@ViewChild('someDialog') someDialog: ElementRef;
and in the .html file, I'm passing the reference back to a function like,
<abc-dialog #someDialog (...
1
vote
1
answer
81
views
HTML element is not found at ngAfterViewInit
I have an Angular component that injects Ace editor. Sometimes in logs (very rare) I can see the following error:
Error: ace.edit can't find div #aceEditor
at ie.edit (https://stepindev.com/ru/...
0
votes
0
answers
11
views
check if DOM element under *ngIf is already rendered
In my Angular 14 App I've got component with canvas in template.
Whole template is under *ngIf checking if data was emitted by Observable.
I need to create Chart using data from Observable and canvas ...
1
vote
2
answers
94
views
Angular go back to page, viewChild is undefined
I have such a sceneario; component A goes to B and when I go back to A , the @viewChild element is undefined. I tried to access it in ngAfterViewInit, ngAfterContentInit but it's always undefined. ...
2
votes
2
answers
79
views
Not able to define same template variable twice in the angular template
I have a query regarding the template variable in angular. Actually I was trying to access multiple elements with the help of the @ViewChildren() decorator.
But when I was defining two element with ...
1
vote
1
answer
57
views
Passing Observables from Child components to ancestors or distant components
I have some serious trouble handling observables in angular (sap composable storefront), that I want to acess from another component. I never seem to get them up to date.
CURRENT STATE
I have cart ...
0
votes
0
answers
24
views
Changes made to the input within the dynamically created component are not reflected in the reference (ComponentReference) in Angular
FundRollingStatisticChartComponent dynamically creates FundRollingStatisticsChartConfigComponent, and it has a reference to the instance of FundRollingStatisticsChartConfigComponent:
this....
0
votes
1
answer
57
views
How to correctly transfer Children to the Angular Directive
I'm trying to pass all FormGroups that are in childrens to my directive. Why are they not transmitted?
I tried using ViewChildren and ContentChildren but the result is undefined
<div block="...
1
vote
1
answer
107
views
How to get instance of attributed directive from an element dynamically in code behind
I'm wondering if there any way to get instance of a directive on DIV element?
There's lots of divs, and I would not like handle a list in component.
<div class="item"
(click)="...
1
vote
1
answer
56
views
How do I pass $event object from Angular TS file?
I have the below code which i am using to expand or collapse the elements
<div class="accordion" (click)="toggleAccordian($event, i)">
clickMenu(event: any, index: any) {
...
0
votes
1
answer
84
views
Difference between EventEmitter and ViewChild('child-form') to get value from child component
In child component, by using EventEmitter we can pass value from child component to parent component.
But I see another case, when we declare ViewChild as below:
@ViewChild('childForm') formComponent: ...
1
vote
1
answer
534
views
Angular ViewChild not initialized for child standalone component
I have a parent component marked as standalone.This consumes another child component which is also standalone. Both the parent and child display successfully.
However, the ViewChild variable is never ...
0
votes
0
answers
60
views
Angular Karma Jasmine Unit Test: TypeError: this.errorDialog.close is not a function
I have following error during simple unit test in Angular/Jasmine/Karma.
TypeError: this.errorDialog.close is not a function
I have viewchild with close function. I would like to test close method.
...
1
vote
1
answer
356
views
Angular 15: Pass data to child component from parent
I'm learning Angular, so forgive me if my terminology isn't quite accurate. I've provided a full version output at the bottom of this post.
This is what I have right now, and it successfully triggers ...
0
votes
1
answer
159
views
How to reload a component while in another one?
I don't know how to use ViewChild feature in my Angular 17 project.
What i'm trying to do is to reload a component when using a function from another component:
Imagine having Component A and ...
1
vote
1
answer
877
views
Why is my reference to ViewChild undefined when mocking the ViewChild
I have an Angular standalone component that has a child standalone component.
In my unit test I want to mock said child component. When I check if the mocked component is rendered via fixture....
2
votes
1
answer
487
views
How to get element reference of ng-select in angular
I am trying to use enter key press event in angular and I am using ng-select for dropdown list but I am not able to get element reference of ng-select as it not native element of HTML ,I did use @...
0
votes
1
answer
256
views
Angular Dropdown Filter - Button
I require dropdown filters, that use Mat-Select directives, to be invoked and displayed by a button instead of the input field. Also i want to hide the input field so that only the button is visible ...
0
votes
1
answer
260
views
Angular How to put elementRef of child component into itself?
I have a parent component, with a child component.
@Component({
selector: 'app-parent',
templateUrl: './parent.component.html',
styleUrl: './parent.component.scss'
})
export class ...
0
votes
3
answers
567
views
Angular - ViewChild of dynamic created Component is undefined
I want to open a component from a service without having to add that component to every other component which has the service.
In the service I have the following:
@Injectable({
providedIn: 'root',
}...
0
votes
1
answer
432
views
I want to get element via ViewChild in TS file, Angular version is 15
When I try to log a ViewChild element in ngAfterViewInit() or ngOnInit() it logs undefined in the console.
HTML file:
<input type="number" #phoneNumber>
TS file:
@ViewChild('...
0
votes
0
answers
605
views
ViewChild is returning undefined (Angular 16)
I know there are several topics on the matter, but I swear I read them all and none solved my issue.
Here is what I have, very much simplified
AdministracionComponent.ts
export class ...
1
vote
0
answers
128
views
TypeError: this.modal.nativeElement.present is not a function at myComponent.ngAfterViewInit
My Component code snippet:
export class MyComponent {
//reference to modal (a UI component of external library)
@ViewChild('modal') public modal: ElementRef;
constructor(private zone: NgZone) {}
...
0
votes
0
answers
84
views
View-Child for the child component returns undefined
I have a Parent Component and a child component which I am trying to access via @ViewChild...This was a legacy code that stopped working after I moved from Angular 5 to 13
Parent
@Component({
...
0
votes
1
answer
78
views
Error accessing inherited class method with @ViewChild in Angular
I'm facing an issue with my Angular application. I have a component hierarchy where I'm trying to access a method from an inherited class using @ViewChild, but I'm encountering an error. It works well ...
0
votes
0
answers
31
views
Filterchange function in viewchild is undefined
I am working on kendo ui angular multiselectdropdown. I have used view child decorator to write business use case for this purpose. If I call asObservable on viewchild filterchange method i am getting ...
0
votes
1
answer
679
views
Angular: How to read ViewChild of a dynamically loaded component
I have a component which has view child like this
@ViewChild('overView') content: ElementRef;
I am loading this component dynamically like this
var overviewComponent = this.vcr.createComponent(...
0
votes
1
answer
1k
views
Angular dynamically add component with injector to specify service
I need to dynamically add some components in Angular 14, and I want to be able to control which implementation of an abstract service each component gets, based on some param I have available when I'm ...
0
votes
1
answer
87
views
Property 'divElem' has no initializer and is not definitely assigned in the constructor when using Template Reference Variable in V16
I have an div element in template and wanted to access the element by template reference variable.But i was facing the issue, it throws some error.
This is my div element
<div (click)="...
0
votes
3
answers
755
views
Div id is null when using ngAfterViewInit
In my application I am using angular, and I am trying to access a div right after the page loads. I have imported Afterviewinit like so:
import { Component, OnInit, ViewChild, AfterViewInit, ...
1
vote
0
answers
923
views
How to load components dynamically without their Host Wrapper Tag
I'm loading component template during Drop Event using "createComponent()" method of ViewContainerRef class. all works okay but it loads component with it's Host Wrapper (selector) tag. but ...
0
votes
1
answer
332
views
ViewChild in component vs passing in element from HTML
In my Angular 15 application, when I hit the Save button, I need to close the dialog. The dialog is only used in one location in the code...in the save event. So I can do it one of two ways:
Add an @...
2
votes
1
answer
969
views
how to access a directive from another peer component
I have a component and a directive inside a parent component. The parent component template looks like this:
<div>
<child-component></child-component>
<dx-data-grid
...
0
votes
1
answer
1k
views
How to use the swiper 9 pagination with Angular
I'm actually migrating to swiper 9.
I had already faced some problems and asked it here about the swiper 9 migration
Some of the answers help me moving forward.
But now I'm trying to use the ...
0
votes
1
answer
381
views
@ViewChild is undefined in afterViewInit using FormControl
I have an nbInput with FormControl:
https://akveo.github.io/nebular/docs/components/input/overview#nbinputdirective
I want to access this in controller using @ViewChild but it returns undefined. ...
0
votes
1
answer
2k
views
Angular ViewChild is undefined - why?
I tried to implement (to test my skills) my own toast message service - dynamically add my toast message to the page. I developed a toast message service - which (I think) is not important here (...
0
votes
1
answer
117
views
Angular @ViewChild: keep whitespace when referring to innerHTML
I use a templateRef and ViewChild() decorator to retrieve and display the innerHTML of an element. But all whitespace and linebreaks are gone when displaying it, it's just a long string.
Example:
in ...
1
vote
0
answers
99
views
Angular ViewChild with ng-template not get all innerHTML
I have this angular component.html
<div #statsToCopy>
<ng-template #modalCumulativePreview let-modal>
<div class="modal-body px-1 cumulative-image-preview" ...
0
votes
2
answers
3k
views
Cannot read properties of undefined (reading 'nativeElement') In Angular
Hi While using ElementRef in Viewchild() I am facing an error. Please see the below error and let me know what is an issue.
I also used ngAfterViewInit() but this error can not be resolved.
import { ...
3
votes
1
answer
553
views
Using @View Child in component file getting undefined value of prime-ng paginator
@ViewChild('paginator', {static: true}) paginator:Paginator;
this paginator is undefined when I console in ngOnInit function.
why?
I tried to print prime-ng paginator in component file with using ...
0
votes
1
answer
198
views
<ng-scroll> @viewchild is undefined
in this code i given dayavailablescroll reference but in ngafterviewinit it is showing undefined
<div class="shifts-rightTable " style="background-color: yellow" [ngClass]=&...
0
votes
1
answer
539
views
Clone a div with renderer 2 and angular
Good morning,
I am having a problem with viewchild which cannot find my selector in my html code. The goal is to look for my 'field' selector in my html to clone it and add a new class to it each time ...
0
votes
2
answers
1k
views
Acces @ViewChild NgForm refence from child components in parent component
I have following app structure:
+--------------------------------------------+
| Parent | ...
0
votes
1
answer
872
views
Angular @ViewChild Directive stays undefined
[EDIT: SOLUTION]
I did not import the right Directive in my app.module.ts
After including like the following, it just works and does not return undefined. :)
import { PlaceholderDirective } from '....
0
votes
1
answer
43
views
Viewchild is undefined inside then()
EDIT
The problem was the "async await".
I remove the async await and just return the Promise.
For some reason the then() inside of async await lose the data about objects of class.
Any ...
0
votes
1
answer
2k
views
Access dynamically loaded child component instance
@ViewChild(ComponentType) comp!: ComponentType;
ngAfterViewInit() {
console.log('ComponentType instance', comp);
}
To get hold of a child component's instance, I know that ViewChild can be used as ...
0
votes
1
answer
768
views
Pass data from child to parent when child is rendered through ng-template
I am using @ViewChild to create a child component, through a template reference variable. I would like to pass data from the dynamically created child to its parent, in any way, but preferably using ...
1
vote
2
answers
1k
views
Angular 'nativeElement + viewchild' vs 'document.querySelector' is quite confusing
I have this component:
<div #widget
class="widget">
</div>
@ViewChild('widget') widget!: any;
ngOnInit() {
console.log(this.widget.nativeElement) //returns ...