Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 48980

ion-select selected value in loop

$
0
0

So Im making an app with IONIC. Im using the tag ion-select & ion-select-option to make it possible to select one or multiple options and send these to typescript (works so far).

Now I want that someone is able to edit their options. This means some of the ion-select-option should be [selected] (checked true).

Does anyone know if that is possible? I am using 2 different arrays for this.

user.companies (all the companies a user has added to the application)

blocked.companies (all the blocked companies an used has added to their blocked contact)
I am using user.companies to display all the ion-select-option choices (the companies to select)

If the ion-select-option value exists in the blocked.companies array is should be selected

This is my code. If more clarification is needed please tell me and I will provide it. Thanks

HTML

<ion-select multiple="true" [(ngModel)]="selectedCompanies" class="selectModal" placeholder="Add one or more companies" text="Hello" okText="Ok" cancelText="Dismiss">
    <ion-select-option selected="{{isSelected}}" *ngFor="let company of user.company; let i=index" value="{{company.company_name}}">{{company.company_name}}</ion-select-option>
</ion-select>

Typescript

import { Component, OnInit, Input } from '@angular/core';
import { ModalController} from '@ionic/angular';
import { LoginService } from 'src/app/login.service';

@Component({
  selector: 'edit-blocked',
  templateUrl: './edit-blocked.page.html',
  styleUrls: ['./edit-blocked.page.scss'],
})
export class EditBlockedPage implements OnInit {
  user = this.loginSrvc.user;
  blocked = this.loginSrvc.editNumber;
  blockedToggle: any;
  minDate = new Date().toISOString();
  selectedCompanies = [];

  isSelected = false;

  constructor(private modalController: ModalController, private loginSrvc: LoginService) {}

  }
}

JSON


      "blocked": [
        {
          "id":20,
          "name":"X X",
          "number":"06-12345678",
          "address":"Address",
          "alwaysBlocked":true,
          "companies": [
            "Company1","Company2","Company3"
          ]
        }
     ]

"user": [
  {
      "id": 1,
      "gender": "0",
      "fullname": "X X",
      "number": "06-12345678",
      "mail": "user@company.com",
      "password": "admin1",
      "company": [
        {
          "company_id": 1,
          "company_name": "Company1",
        },
        {
          "company_id": 2,
          "company_name": "Company2",
        },
        {
          "company_id": 3,
          "company_name": "Company3",
        },
        {
          "company_id": 4,
          "company_name": "Company4",
        }

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 48980

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>