"Observed Issue: Ionic2 Array Fails to Update in HTML Display

I am struggling with updating an array in Ionic2 and Angular2. I have tried updating it on the front end but it's not working, even though it updates perfectly on the backend (ts) as confirmed by checking the console. I need assistance with this.

Here is my Component:

import { Component } from '@angular/core';
import { NavController, NavParams, ViewController } from 'ionic-angular';




@Component({
  selector: 'page-modal-filter',
  templateUrl: 'modal-filter.html'
})

export class ModalFilterPage {

  public fil=[];
  public BRANDNAME: any;
  public srts:any;



  constructor(public nav: NavController, public viewCtrl: ViewController, public navParams: NavParams) {
     this.fil = [];
     this.srts="ABCD";
    if (navParams.get('tabName') == 'filter') {
      let data = navParams.get('data');
      data.map(d => {
        for (let op in d.OPTIONGROUP) {
          for (let x in d.OPTIONGROUP[op]) {
            if (x != "UPC") {
              if (!this.fil[x]) {
                this.fil[x] = [];
              }
              if (this.fil[x].indexOf(d.OPTIONGROUP[op][x]) == -1) {

                this.fil[x].push(d.OPTIONGROUP[op][x]);
              }
            }
          }
        }
      })


      console.log(this.fil);


    }

  }

  closeModal() {
    // this.nav.pop();
    this.viewCtrl.dismiss(true);

  }
}

The "fil" array is not displaying on the frontend of the HTML, but the console shows that it is updated correctly.

This is my HTML code: Array "fil" is not showing

<ion-header>

  <ion-navbar color="primary">
    <ion-buttons start>
      <button ion-button (click)="closeModal()">
        <ion-icon name="close"></ion-icon>
      </button>
    </ion-buttons>
    <ion-title>Search Result(105)</ion-title>
  </ion-navbar>

</ion-header>


<ion-content padding class="tab-filter">
  <!--filter list-->
  <pre>{{fil}}</pre>
  <pre>{{srts}}</pre>
  <ion-list class="list-no-border">
    <ion-item>
      <ion-label> PLACE</ion-label>
      <ion-select>
        <ion-option value="">All Regions</ion-option>
        <ion-option value="vn">Vietnam</ion-option>
      </ion-select>
    </ion-item>

    <ion-item class="price-ranger">
      <ion-label>Price</ion-label>
      <ion-input type="text" placeholder="Min"></ion-input>
      -
      <ion-input type="text" placeholder="Max"></ion-input>
    </ion-item>

    <ion-item>
      <ion-label>Free shipping</ion-label>
      <ion-toggle checked="false"></ion-toggle>
    </ion-item>

    <ion-item>
      <ion-label>Once pice only</ion-label>
      <ion-toggle checked="false"></ion-toggle>
    </ion-item>

    <ion-item>
      <ion-label>Sale items</ion-label>
      <ion-toggle checked="false"></ion-toggle>
    </ion-item>

  </ion-list>

</ion-content>

<!--Footer buttons-->
<ion-footer class="category">
  <ion-toolbar position="bottom">
    <ion-buttons end>
      <button ion-button (click)="closeModal()">
        CANCEL
      </button>
      <button ion-button (click)="closeModal()">
        <span ion-text color="gray">APPLY</span>
      </button>
    </ion-buttons>
  </ion-toolbar>
</ion-footer>

Answer №1

I was able to solve my problem by utilizing

this.fil = [];

and changing it to

this.fil={}

Answer №2

The variable {{fil}} you are using in the view is an array, but it seems like you are declaring it as a simple property. Angular doesn't automatically interpret arrays with string interpolation.

To display arrays, you should use *ngFor.

If you want to display the content of console.log as you mentioned, you can modify your code like this:

<div *ngFor="let item of fil">
     <ion-item *ngFor="let color of item.COLOR">
       {{color.propertyName}}
     <ion-item>
     <ion-item *ngFor="let size of item.SIZE">
       {{color.propertyName}}
     <ion-item>
</div>

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

Encountering an error when using Jest and the envalid library to test a React application: process.exit invoked with code "1"

While testing my React/Typescript application with Jest, I encountered an error. I am utilizing the envalid library to manage my environment variables with types and autocompletion: const ENV = cleanEnv(process.env, { | ^ 6 | R ...

Storing information in an array using CodeIgniter

I have been storing my data using an Array, here is an example: Fetching data: $data['address'] = $this->input->post('address'); Saving: $this->load->model('mymodel'); if($this->inscricao_model->mymodel($ ...

Switch the view to a grid layout upon clicking

Using bootstrap 5, I've successfully created a list view: <div class="col"> Click to switch to grid/list </div> Below is the content list: <div class="row mt-3 list"> list view ... ..... ....... </div ...

How to use jQuery to delete specific table rows while keeping the first row safe from removal

Currently, I have a jQuery script that successfully removes table rows when a button is clicked. However, I want to prevent the button from removing the first row of the table. Is there a way to achieve this? $("#remove").click(function(event) { ...

Tips for choosing multiple values from a dropdown menu in Bootstrap CSS version 3

I'm looking to implement a way to select multiple values from a dropdown menu without using the CTRL key. Currently, I am utilizing Bootstrap CSS for styling. Here is the code for my dropdown: <select multiple class="dropdown-menu"> ...

What is the process for resetting a JQueryUI effect animation?

I'm facing an issue with two timer bars that each wind down over a 5-second period. When I try to stop and reset the first timer, it simply continues from where it left off instead of resetting. The desired behavior is as follows: Timer1 starts User ...

Angular 2: Obtaining the caret position in a contenteditable 'div'

Take a look at this code snippet: <div #test (click)="onClick(test)" contenteditable="true"> This text can be edited by the user. </div> @ViewChild('test') el:ElementRef; constructor(private elementRef: ElementRef) {} ...

Dynamic import of a SASS file in VueJS using a variable such as process.env

Is there a way to dynamically import a file using environment variables? I want to include a specific client's general theme SCSS to my app.vue (or main.ts) I'm thinking of something along the lines of: <style lang="sass"> @import"./th ...

At first, the Angular disabled property does not seem to be functioning as

Trying to toggle a button's disabled state based on whether an array is empty or not in an Angular application. The button implementation looks like this: <button (click)="doStuff()" [disabled]="myObject.myArray.length === 0"> ...

Using shortcode to enhance wordpress post content

I am trying to implement a feature similar to the one found at http://jsfiddle.net/theimaginative/gA63t/ within a wordpress post. I have attempted to create a shortcode for inserting this into a post, but I am encountering difficulties. While I have been s ...

Is there a way to make the parent elements invisible when there are no child elements present?

Take this scenario for instance: <ul *ngIf="hasAnyPermission(['A:READ', 'B:READ', ...])"> <li *ngIf="hayPermission('A:READ')"> a </li> <li *ngIf="hasPermission('B:RE ...

Menu that sorts items based on a specified range of values entered by the user

I'm looking to implement a customized filtering dropdown menu, similar to the one showcased on this website Currently, I have functioning filters that can select items based on a specific category. However, I want to enhance the functionality by inc ...

JavaScript forEach functionality is not compatible with Dynamics CRM 2016

I'm currently working on writing some JavaScript code for a ribbon button in Dynamics CRM 2016 that will extract phone numbers from a list of Leads displayed in the Active Leads window. However, I've encountered an error message when attempting ...

angular feature module triggers rerouting only on site refresh

In my app-routing.module.ts file, I have defined the following routes: { path: 'abc', children: [ { path: 'foo', pathMatch: 'full', redirectTo: 'foo/bar', }, { ...

Unable to retrieve the unique identifier for this item

When attempting to retrieve the current ID of an item in a table by clicking the Purchase button and using console.dir, it only displays the first element. I have also tried console.dir for this.id but it returns nothing. function listProducts() { ...

Angular DataTable jQuery

I am a huge fan of jQuery DataTable, but I have come to realize that when using AngularJS, it does not function properly. Instead of displaying the data with pagination, it shows "No data available in table Showing 0 to 0 of 0 entries." I have checked ou ...

Tips for including additional properties to a <button> element using ReactJS and Typescript

Currently, I am in the process of creating a unique component which consists of an ordinary <button> tag and has a new prop called aria-current. The issue at hand is that Typescript is flagging an error stating that this property does not exist with ...

Exploring the hidden contents within the zip file

I have been exploring methods for reading 'zip' files. Two libraries that I have used are zip.js and JSzip. I have successfully viewed the contents of the zip file. However, here lies the challenge: My goal is to identify specific file types ...

Tips on preventing image previews from consuming too much text data while updating a database in Angular 12 using Material UI for image uploads within a FormGroup object

Currently working with Angular 12 and Angular Material for image uploads with preview. I have a formgroup object below, but I'm running into issues with the 197kb image preview text being inserted into the database. Despite trying setValue/patchValue/ ...

Efficient method for deleting a specific item from a JSON object in React.js

Within the REACT JS framework, I am managing a JSON object in the state component "myrecords". The items within this object are organized by their respective Company Names and have the following structure: { "Master Automotives": [ { ...