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:
JavaScript
x
53
53
1
<form class="was-validated" #zoneForm=ngForm id=#zoneForm>
2
<div class=container>
3
<div class="row justify-content-center">
4
<div class="col-5">
5
<div class="card" style="width: 35rem;">
6
<div class="card-header">
7
<div class="row">
8
<div class="col-11">
9
Zone Entry
10
</div>
11
<div class="col-1">
12
<i style="margin-left: -1rem;" class="fa fa-arrow-circle-o-right" aria-hidden="true"></i>
13
</div>
14
15
</div>
16
17
</div>
18
<div class="card-body">
19
20
<div class="row mb-1">
21
<div class="col-12">
22
23
<input [(ngModel)]="code" name="code" type="number" class="custom_form_control custom input" placeholder="ID" style="padding: 0px;"
24
disabled>
25
</div>
26
</div>
27
<div class="row mb-1">
28
<div class="col-12">
29
30
<input [(ngModel)]="zonename" name="zonename" type="text" class="custom_form_control custom-input" placeholder="Zone Name" required>
31
<i class="fa fa-user" style="margin-left: -1rem;font-size: 1rem; color:black;margin-top: 0.25rem;"></i>
32
</div>
33
</div>
34
35
<div class="row ">
36
<div class="col-12 ">
37
<button type="button " class="btn btn-outline-primary" style="margin-left: 90%; " (click)="createZone()">Save</button>
38
</div>
39
</div>
40
41
</div>
42
43
44
45
<!-- </div> -->
46
</div>
47
</div>
48
</div>
49
</div>
50
51
52
</form>
53
the function should be called by clicking Save button
Advertisement
Answer
You could use ngOnChanges()
Example:component.ts file
JavaScript
1
19
19
1
import { Component, Input, OnChanges } from "@angular/core";
2
3
@Component({
4
selector: "child-component",
5
templateUrl: "./child-component.html"
6
})
7
export class MyComponent implements OnChanges {
8
@Input() someHtml: string;
9
10
constructor() {}
11
12
ngOnChanges() {
13
///** WILL TRIGGER WHEN PARENT COMPONENT UPDATES '**
14
15
console.log(this.someHtml);
16
}
17
18
}
19