"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

The error message "SharedArrayBuffer is not defined" occurred when attempting to utilize ffmpeg.wasm

<!DOCTYPE html> <html> <head> <title>TikTok Live Downloader</title> </head> <body> <h1>TikTok Live Downloader</h1> <label for="username">Username:</label> ...

Anti-virus programs are preventing long-standing AJAX connections

Hey there, I have come across something quite strange while developing a web application that relies on long-held HTTP connections using COMET to stream data between the server and the application. The issue I've encountered is that some anti-virus p ...

The Selenium Action class is failing to perform a second mouse hover on the same web element

Actions action = new Actions(Driver); action.MoveToElement(webelement).ClickAndHold().Perform(); The code snippet above is used to perform a mouse hover on a Web Element, and it works perfectly the first time. However, when attempting to do the mouse hove ...

Is there a way to change the border property of an element when clicked, without causing the displacement of other elements?

I'm in the process of creating a webpage where users can choose the color and storage capacity of an item. Only one color/capacity can be selected at a time, and once chosen, it should be highlighted with a border. The issue I encountered is that whe ...

Traversing through each element using Array method

I need to create a redux function that will add a specified number n to the fourth element of an array every time a button is clicked. However, if the element is either L or M, I do not want the addition to occur. For example, starting with this initial a ...

Enable the event listener for the newly created element

I am attempting to attach an event listener to this HTML element that is being created with an API call handleProducts() function handleProducts() { var display = document.getElementById("display") var url = "http://127.0.0.1:800 ...

The Ajax Get Request functions properly when called in a browser, but returns a 302 error when executed within an iframe. What might be causing this discrepancy?

I am currently developing a web application that initiates multiple ajax requests upon startup. The app functions perfectly when executed independently in the browser. However, when I run it within an iframe, one of the ajax requests unexpectedly returns ...

Issue with JQuery Validation: Some checkbox values are not being successfully posted

Currently experiencing issues with validating checkboxes. Utilizing the jQuery plugin validation found here: The scenario is that there are three checkboxes and at least one of them must be checked. The original form code for these checkboxes is as follow ...

Error in Java script due to the combination of Jmeter and Selenium APIs

While using Jmeter in conjunction with Selenium WebDriver, I encountered an unhandled error "016/02/17 16:51:47 ERROR - com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler: :14:94 Expected , but found ; WDS.browser.findElement(pkg.By.cssSele ...

Converting wiki content to HTML with the help of PHP and JavaScript

Looking to convert wiki syntax to html? Check out the techniques discussed in this resource: Below is the source code of my php page that appears to be functioning correctly. Feel free to test it out yourself: <? if(!defined('DOKU_INC')) d ...

Unraveling the Mystery of @Input and @Output Aliases in Angular 2

After researching about the @Input() and @Output() decorators, I discovered that we have the option to use an alias instead of the property name for these decorators. For example: class ProductImage { //Aliased @Input('myProduct') pro ...

When checking for a `null` value, the JSON property of Enum type does not respond in

Within my Angular application, I have a straightforward enum known as AlertType. One of the properties in an API response object is of this enum type. Here is an example: export class ScanAlertModel { public alertId: string; public alertType: Aler ...

Refresh the current page in Next.js when a tab is clicked

I am currently working on a Next.js page located at /product While on the /product page, I want to be able to refresh the same page when I click on the product link in the top banner (navbar) that takes me back to /product. Is there a way to achieve this ...

Ways to stop jQuery from stripping the <script> elements

Is there a way to stop jquery from removing my JS default behavior? function loadPageSuccess(data) { var data = $(data).find('#content'); alert($(data).html()); $("#content").html(data); $("#page").fadeTo(100,1); } function loadP ...

What is the best way to organize code into separate files while utilizing a module that needs to be included in every file?

In this particular scenario, I am utilizing a headless browser with Puppeteer Chrome and MongoDB. Take a look at the following code snippet: var browser = await puppeteer.launch() var page = await browser.newPage() var db = await MongoClient.connect(" ...

Images are failing to render on Next.js

Hello there! I am facing an issue while working on my Next.js + TypeScript application. I need to ensure that all the images in the array passed through props are displayed. My initial approach was to pass the path and retrieve the image directly from the ...

Angular page not reflecting show/hide changes from checkbox

When the user clicks on the checkbox, I need to hide certain contents. Below is the code snippet: <input id="IsBlock" class="e-field e-input" type="checkbox" name="IsBlock" style="width: 100%" #check> To hide content based on the checkbo ...

Conceal All Other Divs upon Clicking on a New Div Bearing the Identical Class

I'm having trouble implementing the feature that closes other divs when I click on a new div with the same class. It seems like it should be straightforward, but for some reason, it's not working for me. Here is the link to the fiddle where I&apo ...

AngularJS $cookies version 1.6.9 experiencing functionality issues

I recently implemented AngularJS $cookies 1.6.9 in my website to handle cookie management. To test it out, I attempted a basic cookie set like this: $cookies.put('myCookieTest', 'test'); var cookie = $cookies.get('myCookieTest&apo ...

Instructions for activating and deactivating a numerical input field with a checkbox

Is there a way to create a pair of a checkbox and number field that are linked together? When the checkbox is clicked, it should disable the associated number field. Javascript File: $(document).ready(function(){ $("input[name=check]").click(function(){ ...