I assume that the endpoint of your URL will return JSON and try to use the returned data to populate your input value.
First import the HttpClientModule depending on your module:
import { HttpClientModule } from '@angular/common/http';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
HttpClientModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Then, from the inside, foo.component.ts
you can insert an instance of HttpClient into the constructor.
constructor(private http: HttpClient){
}
Then you can use the specified HttpClient
instance http
as follows:
this.http.get('https://example.com/?username1=Dr&Organization=Pepper&action=create').subscribe(data => {
console.log(data);
});
}
(myProp
), :
<input *ngIf="myProp" type="text" name="varname" value="myProp">
, *ngIF
, , , myProp
null
undefined
.
- -
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
title = 'app';
name = null;
constructor(private http: HttpClient){
}
ngOnInit(): void {
this.http.get('https://example.com/?username1=Dr&Organization=Pepper&action=create').subscribe(data => {
this.name = data.result.name;
});
}
}
app.component.html
<input *ngIf="name" type="text" name="varname" value="{{name}}">