Access to input attribute

66 Views Asked by At

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?

1

There are 1 best solutions below

0
Laith Bzour On

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;