The updating of the page in Angular 4.4 is not reflecting the changes made to the model

After recently adding a new angular component to an existing codebase, I'm struggling to update the view with changes in the model due to my unfamiliarity with angular 4. Despite looking at similar questions, none of the solutions seem to work for me.

The view is straightforward: it features a select dropdown that determines which logs are displayed on the page. Whenever the select option is changed, it triggers the controller to update the visible logs.

View:

<nb-card size="small">
  <nb-card-header>
    <span>Filters</span>
    <br />
    <span>Log Severity: </span>
    <select id="selectVisibility" [(ngModel)]="severity" (change)="updateVisibleLogs()">
      <option value="all">All</option>
      <option value="ERR">Error</option>
      <option value="WARN">Warning</option>
      <option value="INFO">Info</option>
      <option value="DEBUG">Debug</option>
      <option value="TRACE">Trace</option>
    </select>
  </nb-card-header>
  <nb-card-body>

    <div *ngFor="let log of visibleLogs">
      {{log.msg}}
    </div>
  </nb-card-body>
</nb-card>

Controller:

import { Component } from '@angular/core';

@Component ({
  selector:'my-selector',
  styleUrls: ['./my-selector.component.scss'],
  templateUrl:'./my-selector.component.html'
})

export class MyComponent {

  updateVisibleLogs() {
    let visibleSeverityLevel = this.level(this.severity);
    let shouldBeVisible = true;

    this.visibleLogs = this.visibleLogs.splice(0);

    for (let i = 0; i < this.logObjects.length; i++, ) {
      shouldBeVisible = true;
      if (!isvalid(this.logObjects[i]))
        shouldBeVisible = false;

      if (shouldBeVisible)
        this.visibleLogs.push(this.logObjects[i].msg);
    }
  };

}

If you notice anything wrong, please give me a heads up :) It's likely this will be marked as a duplicate question soon!

Answer №1

After some investigation, I realized that the issue originated in my view.

<nb-card size="small">
  <nb-card-header>
    <span>Filters</span>
    <br />
    <span>Log Severity: </span>
    <select id="selectVisibility" [(ngModel)]="severity" (change)="updateVisibleLogs()">
      <option value="all">All</option>
      <option value="ERR">Error</option>
      <option value="WARN">Warning</option>
      <option value="INFO">Info</option>
      <option value="DEBUG">Debug</option>
      <option value="TRACE">Trace</option>
    </select>
  </nb-card-header>
  <nb-card-body>

    <div *ngFor="let log of visibleLogs">
      {{log.msg}} <------ this needed to be {{log}}
    </div>
  </nb-card-body>
</nb-card>

The variable visibleLogs was originally an array of strings, which meant that each string needed to be displayed individually.

This issue arose when I changed visibleLogs from an array of Objects to an array of strings. In its previous state as an array of Objects, it had a msg property which is no longer present in the updated version.

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

Using React.Fragment in VS Code with TypeScript error 2605 while having checkJs enabled

While utilizing the JS type checking feature in VScode, I encountered an issue with React.Fragment that is being linted with an error: JSX element type 'ReactElement<any>' is not a constructor function for JSX elements. Type 'ReactEle ...

Struggling to incorporate generics into a Typescript method without sacrificing the typing of object keys

Currently, I am working on a method in Typescript that is responsible for extracting allowable property types from an object of a constrained generic type. The scenario involves a type called ParticipantBase which consists of properties like first: string ...

The installation of Angular CLI through npm has unfortunately encountered an error

After following the steps from this post to remove the old installation, I encountered an issue during the last step: [sudo] npm uninstall -g @angular/cli [sudo] npm cache verify [sudo] npm install -g @angular/cli During the final step, I faced difficult ...

Function in nodejs throwing an error: Return type missing

I am facing an issue with this code snippet while trying to compile the application. public async test(options?: { engine?: Config }): Promise<any> { const hostel = new Service({ list: this.servicesList, createService ...

A guide on displaying a dynamically generated HTML string as HTML within an Angular 6 framework

I'm having trouble displaying Dynamic HTML (dropdowns) created with TypeScript. When I attempt to show it using innerHTML, the options appear as text instead of a dropdown menu. {{question.question}} <div [innerHTML]="question.question" c ...

How can I retrieve data during a double-click event in Kendo Grid using Angular?

How can I retrieve data on the doubleClick event in a Kendo Grid? I want to access the same object that is fetched during the selected event, which would be the dataitem at the selected index row. HTML: <kendo-grid #myGrid [data]="gridDat ...

ERROR: Issue detected in the e class under the e_Host - inline template 0:0

As I was upgrading my angular2 project to RC5, a major issue surfaced. Despite reducing all the code to its minimum in order to debug the problem, I couldn't pinpoint its origin. Every request made by my app led to the following error message (as seen ...

There seems to be a lack of information appearing on the table

I decided to challenge myself by creating a simple test project to dive into Angular concepts such as CRUD functions, utilizing ngFor, and understanding HttpClient methods (specifically get and post). After creating a Firebase database with an API key and ...

Incorporating an expansion panel within an Angular Material table row

I'm currently working on incorporating an expansion panel, possibly a new component, similar to the mat-accordion. This will allow for a detailed view to be displayed within a mat-table row upon clicking. To better illustrate this requirement, I have ...

Steps for integrating Cordova-vk plugin into an Ionic 3 project

I am looking to incorporate the cordova-vk plugin into my app, but I am having trouble connecting it to Typescript. vkSdk is not defined I understand that the plugin is located in the node_modules folder. How can I successfully integrate it into my page ...

I must remove the thumb from the input range control

I am looking for a way to remove the thumb from the progress bar in my music player. I have tried various methods without success, and I simply want the progress bar to move forward with color change as it advances based on the Progress variable. For refe ...

Angular - Creating validations for numeric input fields within reactive forms to ensure values fall within a designated range

One issue I am facing in my Angular form is with a numeric input field. The requirement is to set the minimum value as 3 and the maximum value as 10. However, upon loading the form, the default value should be 0. Users are expected to enter values ranging ...

Using Ionic with React to smoothly scroll to a selected item in a list

Ionic Scroll To Specific List Item covers Ionic + Angular. However, the solution provided is tailored to AngularJS. Now, I have a similar question but related to Ionic + React: Assuming a layout like this: <IonContent> <IonList> <Io ...

`Is it possible to integrate npm libraries with typescript and ES6?`

I am looking to focus on using ES6 as the output for a node server-side app that I plan to run on the cutting-edge iojs distribution, which hopefully has support for the latest ES6 syntax. However, I'm unsure about how to integrate standard NPM libra ...

How can you retrieve the keys of an object that conforms to an interface?

In the following demonstration, we have two objects - KEYS and KEYS2. When importing KEYS in index.ts, autocomplete suggestions are available for K1 and K2 because KEYS does not adhere to an interface. On the other hand, with KEYS2, autocomplete is not pr ...

Exploring the relationship between two entities in Angular 7 using Typescript

Creating a Reactive form for user registration in Angular involves setting up the form data object separately from the viewmodel object. https://i.sstatic.net/ERlYa.png export interface RegisterViewModel { UserName: string; Email: string; Password: strin ...

Explain the concept of utilizing curried state handlers within a React and Typescript application

I am currently working on defining the function that will handle change events to update the state value accordingly. This is what I envision the implementation to look like: handleChange: ChangeHandler<State> = field => value => this.set ...

Securing Angular CLI Assets: Implementing canActivate for Protection

I am facing an issue where anyone can access my website's assets using URLs like http://localhost:4200/assets/filename.pdf, even when the user is not logged in. How can I secure these assets by implementing a canActivate guard? An ideal solution woul ...

How do I set up middleware with async/await in NestJS?

I am currently integrating bull-arena into my NestJS application. export class AppModule { configure(consumer: MiddlewareConsumer) { const queues = this.createArenaQueues(); const arena = Arena({ queues }, { disableListen: true }); consumer. ...

Synchronize Angular 5's provision of injection tokens

Is there a way to delay the provision of an InjectionToken until a previous provider's useFactory is finished? For instance, I would like to set MyInjectionToken only after the APP_INITIALIZER token has been allocated. providers: [ HttpClient, MySer ...