Formatting the Return Values of Ionic Select

Having an issue with Ionic 3. Using an <ion-select> element with ngModel="x". When attempting to display the value in the console, it shows with extra spaces and line breaks. I tried replacing line breaks with 'e' and spaces with 'a'. Now the output appears like this:
Output: eaaaaaaaaaaOutputeaaaaaaaaaa

Answer №1

Here is my code snippet:

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
/**
 * Generated class for the AnkerstangePage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more information on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-ankerstange',
  templateUrl: 'ankerstange.html',
})
export class AnkerstangePage {

  constructor(public navCtrl: NavController, public navParams: NavParams) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad AnkerstangePage');
  }

  public moertelChoosen : string = "VMU Plus";
  public kartuschengroesseChoosen: string;

  public stangen : string[] = [
    "M6",
    "M8",
    "M10",
    "M12",
    "M14",
    "M16",
    "M20",
    "M22",
    "M24",
    "M27",
    "M30",
    "M36"
  ];

  public moertel: string[] = [
    "VMU Plus",
    "VMH",
    "VME",
    "VM-EA",
    "VM-PY"
  ];

  public vmuPlus: number[] = [
    150,
    280,
    300,
    345,
    420,
    420,
    825
  ];

  public vmh: number[] = [
    280,
    345,
    420
  ];

  public vme: number[] = [
    385,
    585,
    1400
  ];

  public vmea: number[] = [
    300,
    345,
    420
  ];

  public vmpy: number[] = [
    300,
    410
  ];

  public kartuschengroesse = {
    "VMU Plus": this.vmuPlus,
    "VMH": this.vmh,
    "VME": this.vme,
    "VM-EA": this.vmea,
    "VM-PY": this.vmpy
  };

  public printVal(val: string){
    alert("moertel:" + val.replace("\n", "").replace("          ", ""));
  }

  public changeMoertel(val: string){
    //this.moertelChoosen = val.replace("\n", "");//.replace("          ", "");
    alert(this.moertelChoosen.replace("\n", "e").split(" ").join("a"));
  }

}
<ion-header>

  <ion-navbar>
    <ion-title>Ankerstange</ion-title>
  </ion-navbar>

</ion-header>


<ion-content padding>
  <h3>{{ "titelAllg" | translate }}</h3>
  <h4>{{ "titelAnkInn" | translate }}</h4>

  <ion-list>
    <ion-item>
      <ion-label> {{ "moertel" | translate }} </ion-label>
      <ion-select [(ngModel)]="moertelChoosen" [multiple]="false" (ionChange)="changeMoertel()">
        <ion-option *ngFor="let item of moertel">
          {{ item }}
        </ion-option>
      </ion-select>
    </ion-item>
    <ion-item>
      <ion-label>{{ "kartuschengroesse" | translate }}</ion-label>
      <ion-select [(ngModel)]="kartuschengroesseChoosen">
        <ion-option *ngFor="let size of kartuschengroesse[moertelChoosen]">
          {{ size }}
        </ion-option>
      </ion-select>
    </ion-item>
  </ion-list>

</ion-content>

Do not be surprised by the German words within the code :D

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

An Angular application running on an Azure App Service experiences crashes exclusively when accessed through the Chrome browser

My webapi/angular site is hosted on the same Azure app service, with authentication token and other APIs located at /site/api and the angular app at /site/app. Everything works fine on our staging environment, which is a Windows 2012 VM with IIS 7. The an ...

Tips for sending arguments to react-highcharts?

While browsing through the documentation, I noticed that I can pass config in a certain way: render() { let config = this.config; return ( <div className="column"> <div className="ui segment"> ...

The React function was misusing the useEffect hook, causing it to be

I seem to be encountering a problem when trying to call useEffect within this function. As someone who is relatively new to React, I may have made some noticeable mistakes, but dealing with this issue is becoming quite time-consuming. The function in ques ...

Error encountered while attempting to login to the Winston Logger in the /var/log directory

After hours of attempts, I am still struggling to get Winston to log in my /var/log directory on my Fedora system. I conducted a test project using Express and found that logging works fine within the project directory. However, when attempting to log any ...

How to stop the mobile keyboard from hiding in JavaScript

On a webpage, I have an HTML setup with an editor and buttons positioned above the keyboard: ------------ |1| Hello | |2| World | | | | | | | ------------ |Tab|( ) [ | ------------ |qwertyuiop| | asdfghkl | | zxcvbnm | | [ ] | ------- ...

There is an issue with the Next.js middleware: [Error: The edge runtime is not compatible with the Node.js 'crypto' module]

Struggling with a problem in next.js and typescript for the past 4 days. If anyone can provide some insight or help with a solution, it would be greatly appreciated. Thank you! -- This is my middleware.ts import jwt from "jsonwebtoken"; import { ...

Upon attempting to send a POST request with PostgreSQL, the following error is displayed: "Invalid input syntax for type integer: '12 Pro'"

I encountered an error while attempting to send a POST request using PostgreSQL/Sequelize. Can anyone help me identify the issue in this code? async create(req, res, next) { try { let { name, price, brandId, typeId, info } = req.body; c ...

Jest test is unable to find the definition of Regexp

In the process of testing a module ./main.js with ./__tests__/main-test.js, I encountered an issue. One of the functions in ./main.js utilizes new Regexp(REGEX, 'g'). Upon running jest, an error message is displayed: ReferenceError: Regexp is n ...

best practice for updating a node in ng-zorro-antd tree

I'm attempting to make changes to the node titles in a tree structure. I have learned that the tree will only show these updates if the nodes array is changed by reference (as shown in the example). However, when I update the nodes, the tree flickers ...

Put an end to the endless game of defining TypeScript between Aurelia CLI and Visual Studio 2017 builds

I am encountering TypeScript errors in my Visual Studio build for an Aurelia project within a .NET Core project. The errors include 'Build:Cannot find name 'RequestInit'', 'Build:Cannot find name 'Request'', and &apo ...

Choosing just the element that was clicked and added to the DOM

I've been experimenting with JQuery in a web app I'm developing. The app involves dynamically adding elements to the DOM, but I've encountered an issue with click events for these newly added elements. I'm looking for a way to target an ...

Using the -g flag in Node.js consistently results in error messages

Whenever I attempt to install something globally with node, I encounter a series of errors. Interestingly, when I tried it in Powershell, no errors were thrown, but I suspect this is due to the fact that I was using Powershell instead of the official Node ...

Can someone help me troubleshoot the issue with my submit button's onclick function?

I am currently working on a project where I have a content box enclosed in a div tag. Within this content box, there are paragraphs with unique IDs for individual styling rules. I have set margins, padding, and other styles accordingly. At the bottom of th ...

Error message thrown by node express.js indicating that response headers cannot be reset once they have been sent

As a newcomer to both node and express, I may be making a silly mistake. If you want to see the complete source code, please visit: https://github.com/wa1gon/aclogGate/tree/master/server logRouter.get("/loggate/v1/listall", function(req, res) { let ...

An issue occurred when retrieving the input value during a (change) event within a nested *ngFor loop in Angular

Within my table, I have implemented a nested loop using the *ngFor directive: <tbody> <tr *ngFor="let dept of salesTarget; let i = index"> <td>{{dept.dept}}</td> <td *ngFor="let month of monthList; ...

What is the best way to combine two arrays and generate a new array that includes only unique values, similar to a Union

Here are two arrays that I have: X = [ { "id": "123a", "month": 5, "markCount": 75 }, { "id": "123b", "month": 6, "markCount": 85 ...

Ways to identify when all images have been loaded during a dynamic page load

I am trying to load a page with images into a div element. I need to find out when all the images on that dynamically added page have finished loading. $("#main").load('imagespage.php', function(){ alert("Page loaded"); }); The problem is that ...

Tips for organizing a search using two keys in Javascript

I am dealing with a large dataset containing over ten thousand objects that hold information about two different ids as shown below: dataSet = [ { ids: ["123", "234"], information: 1 }, { ids: ["123", "345"], in ...

Changing a single state in React results in the modification of both states simultaneously

Whenever I attempt to modify one state, I find that another state is inexplicably changing as well. I've scoured my code for the issue but can't seem to pinpoint it. What steps should I take next? Here's the snippet of code in question: impo ...

What are the reasons behind the restriction on using non-public members in TypeScript classes?

Consider the following scenario: class Trait { publicMethod() { this.privateMethod(); // do something more } private privateMethod() { // perform a useful action } } When attempting to implement it like this: cla ...