Importante

martes, 2 de mayo de 2023

enlaces bidirecional two way data biding

 importe for modele en app.module


import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { ButtonComponent } from './button/button.component';
import { FormsModule } from '@angular/forms';

@NgModule({
  declarations: [
    AppComponent,
    ButtonComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    FormsModule
  ],
  providers: [],
  bootstrap: [AppComponent]


II coloque un imput y coloque en ng ngModel e iguale a la propuiedad que desea crear

<input type="text" [(ngModel)]=" name">

note que la propiedad a usar será el name

III. Cree la propiedad nombre en el app cpmponen  y dejalo vacio


import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  title = 'retoD1';
  url = 'https://cdn.pixabay.com/photo/2017/10/17/16/10/fantasy-2861107_1280.jpg';
  name!:string;
}

Recuerdo guardar todos los datos


por otro lado a name se le puede dar un valor dpor defecto por ejemplo 

export class AppComponent {
  title = 'retoD1';
  url = 'https://cdn.pixabay.com/photo/2017/10/17/16/10/fantasy-2861107_1280.jpg';
  name = 'Gersom'
}








0 comentarios:

Publicar un comentario