Hello,
I'm new to angular and promise/observable and i am trying some basic example to understand them. Here is my example:
I have an interface with 2 promise fields:
export interface Credential {
readonly uname: Promise<string>;
readonly pwd: Promise<string>;
}
A service with a method that return the instance of the interface above:
@Injectable({
providedIn: 'root'
})
export class UserService {
public getCredential(): Credential {
let _uname = this.secureStore.get("uname");
let _pwd = this.secureStore.get("pwd");
return { uname: _uname, pwd: _pwd };
}
}
A component that call the service to get the credential object:
@Component({
selector: 'app-home',
templateUrl: './home.page.html',
styleUrls: ['./home.page.scss'],
})
export class HomePage implements OnInit {
credential: Credential;
constructor(private userService: UserService) { }
ngOnInit() {
this.credential = this.userService.getCredential();
}
}
Finally my template:
{{ credential.uname | async }}
I'm not sure why there is nothing printed on the screen. Is it normal to have a promise inside an object like the way i define my interface?
Thai