0

I'm trying to access to an atribute value with Angular, using @Input, but is always undefined.

<ion-input type="text" placeholder="{{dat.nombre}}" [miName]="'hola'" label="" [(ngModel)]="nombre"></ion-input>
<div class="btnSmt">
    <ion-button class="btn1 color-primary-btn" (click)="envDatos()">Actualizar Datos</ion-button>
</div> 
import { Component, Input, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { HttpClient } from '@angular/common/http';

@Component({
  selector: 'app-ficha-ub',
  templateUrl: './ficha-ub.page.html',
  styleUrls: ['./ficha-ub.page.scss'],
})
export class FichaUbPage implements OnInit {

  id: any;
  nombre!:string;
  @Input('miName')miName!:string;

  constructor(private activatedRoute: ActivatedRoute, private http: HttpClient) { }

  ngOnInit() {

  }

  envDatos(){
    console.log(this.nombre)
    console.log(this.miName)
  }
}

I've tried all the things that says this page: https://www.youtube.com/watch?v=I-EAMQFgQy4 but nothing works.

I'm trying to send the value of the input if is full, and another value (placed into the atribute) if is empty.

You know if there is another way?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • can you share on stackblitz – DEV Jul 14 '23 at 10:59
  • 1
    Are you aware that you are passing the value to a `ion-input` and not to your custom `app-ficha-ub` component? – Fabian Strathaus Jul 14 '23 at 11:07
  • Yes, because is a form where there are going to be more inputs, and I have to get their values and atribute too. – Violeta Quintanilla Jul 14 '23 at 11:10
  • Your component selector is app-ficha-ub. So miName input is an input for this html component tag: What kind of dictionary, you use, which contains this input selector: ion-input? Can you paste its documentation? (Oh it's ionic, i think :D) – faklyasgy Jul 14 '23 at 11:10

1 Answers1

0

why using @Input,[(ngModel)] work fine to get the input value other way to get it use @ViewChild like below

@ViewChild(IonInput, { static: false }) miName: IonInput | null = null;