Having trouble updating properties of child components in Angular

I have a data filtering functionality where I enter values in a filter popup and successfully retrieve results. I then store this data in local storage to retain it when navigating back from another page. However, upon returning to the filter component, I encounter an error: "Cannot set property 'status' of undefined at SearchUserGridComponent.autoFillAdvanceSearch". I have been struggling with this issue and would appreciate any assistance. Below is the relevant code snippet.

**SearchUserGridComponent.ts**

@ViewChild('callDialog', { static: true }) callDialog: TemplateRef<any>;

openUserAdvancedSearchPopup() {
        let dialogRef = this.dialog.open(this.callDialog,{
          width: "80vw",
          maxWidth: "1366px",
          disableClose: true
        });
      }

**search-user-grid.component.html**

<ng-template #callDialog let-ref>
    <div *ngIf="design?.is_advanced_search_enabled" class="advanced-search" [ngClass]="{'show-advanced-search':showAdvancedSearch}">
        <advanced-user-search-component *ngIf="searchColumns?.length>0" [columns]="searchColumns" [dropDown]="dropDown"
            (getSearchedParams)="getSearchedParams($event)" (getSearchedTerms)="getSearchedTerms($event)"
            backgroundColor="rgba(190, 190, 190, 0.4)">
        </advanced-user-search-component>
    </div>
   </ng-template>

**advanced-user-search.component.ts**

search() {
        debugger
        let params = new HttpParams();
        if (this.status != null && this.status != "A") {
            if (this.status == "AC") {
                params = params.append('isActive', "" + true)
            }
            else if (this.status == "I") {
                params = params.append('isActive', "" + false)
            }

        }
        ...

When the user clicks the back button, the following methods are called on search-User-Grid.component.ts

**SearchUserGridComponent.ts**

 ngAfterViewInit() {
  if (this.isBack == "true" && this.design.screen_name == "searchUsers") {
            this.showAdvancedSearch = true;
            this.autoFillAdvanceSearch();
          
        }
}
...

 autoFillAdvanceSearch() {
        let userSearchData = JSON.parse(localStorage.getItem("userSearchData"))
        if (userSearchData != null && userSearchData != undefined) {
            ...

Answer №1

If you are receiving this error, it indicates that the advancedSearchComponent is not defined in your code. This suggests that the viewchild is unable to locate any element with the id advancedSearchComponent. To resolve this issue, simply include #advancedSearchComponent within your

<advanced-user-search-component></advanced-user-search-component>
and the problem should be resolved.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Refreshing an Angular2 page after successfully passing an object to a component

I am facing a challenge in refreshing a page to show the selected value from a table in another component's template. Below is a snippet of code that I have created to illustrate the issue. There are two components involved: TableComponent: This c ...

What is the best way to choose a dropdown item at random from a list using Angular 5?

My current setup involves a list that looks like this... export const inventory= [ 'coffee' 'tea' 'wine' 'beer' 'sake' .... ]; Within the HTML, I am using a loop to create dropdown menus a set number of t ...

Error message: Object literal is limited to declaring existing properties

The source code was obtained from this Codesandbox demo: CodeSandbox - Cover Image Example Subsequently, an .eslintrc configuration file was generated with the following content (the only content present): { "extends": "react-app" } However, a TypeScri ...

Tips for seamlessly embedding Youtube iframes within Angular2 components. Resolving issues with unsafe value errors

ERROR: There seems to be an issue in the ./HomeComponent class HomeComponent - inline template:23:84. It is caused by using an unsafe value in a resource URL context. About my homeData model { id: 1, title: '2017 Super Bowl', graphic: 'ht ...

Is your async function lacking a return statement?

After completing the development of a new method for a bug I encountered, I noticed something interesting. Despite the fact that there is a potential scenario where the function may not return anything, the compiler did not flag any errors. It got me think ...

Leveraging Angular App with the Bootstrap .modal() JQuery method

I'm encountering issues with Bootstrap 4 and NPM/Angular CLI when using the .modal methods Error: TypeError: $(...).modal is not a function Main.ts: import * as $ from 'jquery'; import * as bootstrap from 'bootstrap'; App.compo ...

Confirming changes to checkbox values in Angular 2 prior to updating

My current challenge involves implementing a confirmation dialog in my application, and I'm feeling a bit unsure about the logic behind it. UserDetailsComponent.ts import { Component, OnInit, OnDestroy, ViewChild, Input, OnChanges, SimpleChange } f ...

After the component has been initialized for the second time, the elementId is found to be null

When working with a component that involves drawing a canvas chart, I encountered an issue. Upon initializing the component for the first time, everything works fine. However, if I navigate away from the component and return to it later, document.getElemen ...

Guide on implementing Observables in Angular 2+ to update a single entry in a table in real-time

I'm facing a challenge with my Angular4 and Node.js application. I have a table that displays data with 7 columns using *ngFor. The issue arises when I need to update the last column dynamically and in real-time. Specifically, I want to show a green c ...

Discover a Simple Trick to Enhance tsc Output: Unveil the Art of

When I work on a TypeScript project, I typically use the watch mode of the compiler: tsc --watch However, one issue I face is that it's challenging to identify errors in the output since they are displayed as plain text: Sometimes I don't even ...

What could be causing the sorting function to malfunction on certain columns?

My table's column sorting feature works well with first name and last name, but it seems to have issues with dl and dl score columns. I need assistance in fixing this problem. To access the code, click here: https://stackblitz.com/edit/angular-ivy-87 ...

The type 'Observable<Student[]>' is lacking important properties such as id, first_name, last_name, English, and more within the type 'Student'

I have developed two components (table and form) and I am working on transferring data from the form component to the table component when editing. The code that I have written is currently throwing an error. However, when I check the console using console ...

Issue with tooltip not displaying attribute data-bs-title in Angular 17 with Bootstrap version 5.3

I am currently developing an Angular version 17 application and implementing a dynamic tooltip feature. The tooltip content will be supplied through a @Input() into the component. While a static tooltip works fine, I am facing an issue when trying to make ...

What is the best way to remove a specific row from an Angular Material table that does not have any filters

Here is my samplepage.component.ts code: import { Component } from '@angular/core'; @Component({ selector: 'app-batchticketvalidation', templateUrl: './batchticketvalidation.component.html', styleUrls: ['./batchtic ...

Send data to assembled Angular directives

Using a third-party directive "A" with inputs a1 and a2, I am looking to create a new directive "B" that acts as a facade for "A". The goal is to set specific values for "A" within "B" so that configuring the inputs each time "A" is used is not necessary. ...

The updating of Angular 2 CLI variables does not occur

As a complete newcomer to Angular 2, I recently attempted to start my first project using the Angular CLI. Unfortunately, I encountered some issues. It seems that the variables in my views are not updating as expected. I followed the typical steps: ng n ...

Troubleshooting problem with Webpack and TypeScript (ts-loader)

Seeking help to configure SolidJS with Webpack and ts-loader. Encountering an issue with return functions. What specific settings are needed in the loader to resolve this problem? import { render } from "solid-js/web"; const App = () => { ...

What is the best way to set the generics attribute of an object during initialization?

Below is the code that I have: class Eventful<T extends string> { // ↓ How can I initialize this attribute without TypeScript error? private eventMap: Record<T, (args?: any) => void> = ? } Alternatively, class Eventful<T extends st ...

The compiler-cli encounters an error when it comes across dynamic declarations

I have encountered a significant project that was designed with the anticipation of transitioning to Angular 2.0 and enabling AoT compilation. After obtaining all the necessary API from Angular, I found that the project worked smoothly in JiT mode with Ang ...

"Users have reported that the file upload preview feature in Angular 6 only works after the

I am currently utilizing Angular 6. In my application, I have a simple input type="file" field that passes data to an image source which displays the image I intend to upload. The issue I am facing is that when I select an image for the first time, nothi ...