It's been hours since I am trying to figure out solution to create objects. can't find anything online. I am not able to access user1 outside of the constructor. Please help.
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'app-first-folder',
templateUrl: './first-folder.component.html',
styleUrls: ['./first-folder.component.css']
})
export class FirstFolderComponent implements OnInit {
nameVar:string;
passwordVar:string;
@Input() test:string;
constructor() {
interface UserInface{
name:string,
password:string
};
var user1: UserInface;
}
ngOnInit() {
}
//function for button click
submitBtn(){
**//I am getting error here because i am trying to assign values to object.**
**//error "Property 'user1' does not exist on type "**
this.user1.name = this.nameVar;
this.user1.password = this.passwordVar
}
}
thisin the submitBtn? Is it instance ofFirstFolderComponentclass?User. If you need a new user object/instance just create it withthis.user = new User();the user class can serve as kind of interface too. You can still use the object literal to create a new user object if you want:this.user = {name : 'thename', password: 'thepw'}