#Variable assigned inside subscribe is undefined outside subscribe
8 messages · Page 1 of 1 (latest)
g!codeblock @fast quarry Don't do that. Use the AyncPipe to get values out of an Observable in Angular. Also show code for better advice
The reason behind doing it in typescript is because I am using a form builder and need one of the input values to be a specific string but formcontrolname wont let me input a value
show code
@fast quarry, you can use the following snippet to have your code formatted and colored by Discord. Replace ts with the language you need (i.e. html, js, css, etc)
```ts
// your code goes here
```
Observable subscribe:
test.subscribe(element => {
return element.test;
})
HTML:
<form [formGroup]="testForm" (ngSubmit)="onSubmit()">
<fieldset class="uk-fieldset">
<div *ngFor = "let t of test | async" class="uk-margin">
<input id="test"
formControlName="test"
class="form-control"
[value]="t.test"
type="text"
placeholder="test"
aria-label="Input">
</div>
</fieldset>
</form>