Beginning with Angular, I am curious about the process of passing an object (connectedUser) from the LoginComponent to the ProfileComponent.
Your help is greatly appreciated. Thank you in advance.
Beginning with Angular, I am curious about the process of passing an object (connectedUser) from the LoginComponent to the ProfileComponent.
Your help is greatly appreciated. Thank you in advance.
Here is a different approach to try:
create Class RegistrationComponent {
userData = {}
}
within the HTML template :
<app-registration-component [info]="userData"></app-registration-component>
inside the registration Component :
create class RegistrationComponent {
@input() info : any; // Data is received here
}
If you're looking for a way to implement this functionality, here's one approach you can take. Start by creating a service called AppStateService (in app-state.service.ts) that will hold and share an object. Feel free to use the code snippet below as a reference:
Here is the content of app-state.service.ts file:
@Injectable({
providedIn: 'root',
})
export class AppStateService {
private _connectedUser: any = undefined;
public get connectedUser(): any {
return this._connectedUser;
}
public set connectedUser(value: any) {
this._connectedUser = value;
}
}
Within your login.component.ts file, you can access the AppStateService like this:
constructor(private appState: AppStateService) { }
public onLoggedin(): void {
this.authService.login(username, password).subscribe(res => {
this.appState.connectedUser = res.data;
});
}
In your profile.component.ts file, retrieve the connected user information using the following code:
public connectedUser;
constructor(private appState: AppStateService) { }
ngOnInit(): void {
this.connectedUser = this.appState.connectedUser;
console.log('I:--START--:--ProfileComponent OnLoad--:connectedUser/', connectedUser);
}
I'm encountering an issue with Mat-datepicker in my Angular app. When I manually input the date into the field, it doesn't parse in the correct locale, but it displays correctly when selected from the month view. Recently, I made the switch from ...
Issue I have been facing challenges while testing my Angular 6 application with Karma. I am encountering errors such as: Can't bind to 'ngModel' since it isn't a known property of 'mat-select'. Although the import works in ...
My current project involves a component that resembles a spreadsheet, with numerous elements using two-way binding [(ngModel)] to a mutable object. However, when the number of inputs exceeds 100, the UI starts to slow down. After profiling the application ...
My Angular Universal application (version 5.2.11) is currently hosted on Heroku, running on a Node server using express. I have implemented rate-limiters in all my POST routes to restrict requests by IP address, checking the request's IP through req.h ...
I am looking for an alternative approach using the v-date-picker component. My requirement is to allow users to only select the year and month, and then close the date picker menu automatically. Below is an example of my HTML code, but I am open to using ...
Imagine a scenario where there is a predefined type: interface Test { foo: number; bar?: { name: string; }; } const obj: Test; // The property 'bar' in the object 'obj' is currently optional Now consider a situatio ...
Is it possible to determine the index of an item within a nested array without knowing how deeply nested it is? For example, given the array arr=[a,[b,[c],[d],e],f,[g],h]. ...
I am encountering an issue with my TypeScript code. Inside the anonymous functions, I am unable to change the properties of the class because they are out of scope. Is there a way to pass them in so that they can be modified? class PositionCtrl { ...
I'm currently working on a scenario where I need to implement logic for checking or unchecking a checkbox in React Native. If the checkbox is checked, I want to print one string, and if it's unchecked, I want to print something else. How can I ac ...
I have experimented with different methods, but none seem to be effective: <button md-icon-button color="primary"> <md-icon md-svg-src="./assets/img/sprites.svg">menu</md-icon> </button> and also tried this: <md-icon svgSrc= ...
I need assistance in creating a function that can update an object's value based on the provided key and new value while ensuring type safety. type GroceryStore = { isOpen: boolean; offers: string[]; name: string; }; const myGroceryStore: ...
Currently, I am working on a project with Next 13.5 using react-hook-form and shadcn-ui. The issue that I have encountered is that creating a form involves too much redundant code. To address this, I abstracted the FormProvider and Input component. The pr ...
Currently, I am a student learning about react. During the course of working on a project, I encountered a problem that left me with a question. {pages.map((page, idx) => ( <li key={page.page_id} id={`${idx + 1}`} css={CSSCarouselItem}> < ...
Is there a way to display an element only when a specific function is executed or a particular click event occurs? Here's the html code snippet I'm currently working with: <sebm-google-map [latitude]="lat" [longitude]="lng" [zoom]="zoom" [map ...
I am currently working with an Angular application. Within this application, I have a reactive form that is declared as form!: FormGroup<GlobalBean> Within the GlobalBean interface, there is an array of another bean defined as: export interface Glo ...
`The CORS policy has blocked access to the XMLHttpRequest at 'http://localhost/phpfile/leave-option.php' from the origin 'http://localhost:8100'. This is due to the absence of the 'Access-Control-Allow-Origin' header on the re ...
I've been trying to incorporate a 3D model view into my website using the stl-model-viewer provided at: https://www.npmjs.com/package/angular-stl-model-viewer Despite following the installation steps, it seems that I'm unable to get it to work. T ...
Explore the example here: https://codesandbox.io/s/wandering-wildflower-764w4 Essentially, my goal is to achieve the following: In the provided example, I have a server validation function that has been mocked. My objective is to maintain the state local ...
When the following code snippet is executed: @Mutation remove_bought_products(productsToBeRemoved: Array<I.Product>) { const tmpProductsInVendingMachine: Array<I.Product> = Object.values(this.productsInVendingMachine); const reducedPro ...
My project has a specific folder structure as shown below: https://i.sstatic.net/7oihC.png In my list-page, I perform operations such as create, update, and delete using modal dialogs. I am considering creating 4 pages for each of these CRUD operations a ...