Can anyone help me figure out why I keep getting a 'set property of null' error while attempting 2way binding in my interface?
Whenever I submit the form and trigger the onSave function, I encounter the error "Cannot set property 'googleUri' of null". The console indicates that it's outputting null. How can I resolve this issue while still utilizing my interface?
This is the structure of my interface
export interface User {
googleUri?: string;
}
This is how my component HTML looks like
<form name="form" (ngSubmit)="onSave()" #f="ngForm" novalidate>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="googleUri">Google Excel Address</label>
<input type="text" class="form-control form-control-lg" name="googleUri" id="googleUri" [ngModel]="user?.googleUri" (ngModelChange)="user.googleUri=$event"/>
</div>
</div>
</div>
</form>
This is the TypeScript code for my component
export class ProfileComponent implements OnInit {
private user: User = {};
public loading: boolean = false;
constructor(private userService: UserService) { }
ngOnInit() {
}
private onSave(): void {
console.log(this.user);
this.userService.saveUserSettings(this.user)
.subscribe(
data => console.log(data),
err => console.log(err),
() => this.loading = false
);
}
}