Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
163
rated 0 times [  165] [ 2]  / answers: 1 / hits: 14306  / 4 Years ago, wed, august 19, 2020, 12:00:00

I have a page for create operation. In my page I have 1 form with 2 field. If I reload the page (or window.reload by code) I can see updates in that form. But I want to trigger a refresh on the form by pressing button click.


So please help me to write a function that can refresh the form (or any other html element like tabe/paragraph/etc.)


.html of my form:


<form class="was-validated" #zoneForm=ngForm id=#zoneForm>
<div class=container>
<div class="row justify-content-center">
<div class="col-5">
<div class="card" style="width: 35rem;">
<div class="card-header">
<div class="row">
<div class="col-11">
Zone Entry
</div>
<div class="col-1">
<i style="margin-left: -1rem;" class="fa fa-arrow-circle-o-right" aria-hidden="true"></i>
</div>

</div>

</div>
<div class="card-body">

<div class="row mb-1">
<div class="col-12">

<input [(ngModel)]="code" name="code" type="number" class="custom_form_control custom input" placeholder="ID" style="padding: 0px;"
disabled>
</div>
</div>
<div class="row mb-1">
<div class="col-12">

<input [(ngModel)]="zonename" name="zonename" type="text" class="custom_form_control custom-input" placeholder="Zone Name" required>
<i class="fa fa-user" style="margin-left: -1rem;font-size: 1rem; color:black;margin-top: 0.25rem;"></i>
</div>
</div>

<div class="row ">
<div class="col-12 ">
<button type="button " class="btn btn-outline-primary" style="margin-left: 90%; " (click)="createZone()">Save</button>
</div>
</div>

</div>



<!-- </div> -->
</div>
</div>
</div>
</div>


</form>

the function should be called by clicking Save button


More From » html

 Answers
4

You could use ngOnChanges()


Example:component.ts file


import { Component, Input, OnChanges } from "@angular/core";

@Component({
selector: "child-component",
templateUrl: "./child-component.html"
})
export class MyComponent implements OnChanges {
@Input() someHtml: string;

constructor() {}

ngOnChanges() {
///** WILL TRIGGER WHEN PARENT COMPONENT UPDATES '**

console.log(this.someHtml);
}

}

[#2861] Saturday, August 15, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
neildrews

Total Points: 166
Total Questions: 103
Total Answers: 85

Location: Moldova
Member since Sat, Aug 6, 2022
2 Years ago
neildrews questions
Fri, Feb 18, 22, 00:00, 2 Years ago
Tue, Oct 12, 21, 00:00, 3 Years ago
Tue, Mar 23, 21, 00:00, 3 Years ago
Sun, Aug 16, 20, 00:00, 4 Years ago
Sun, Jul 12, 20, 00:00, 4 Years ago
;