Q: How do you pass data from a child component to a parent component in Angular?
A: Use @Output() with EventEmitter in the child component and bind to the emitted event in the parent using (eventName)="handler($event)".
This is the standard Angular mechanism for child-to-parent communication.
Q: How do you pass data from a Parent component to a Child component in Angular?
A: In Angular, data is passed from a Parent Component to a Child Component using the @Input() decorator.
The parent binds a value to the child component's input property using property binding syntax [property]="value", and the child receives it through an @Input()
property.
Simple Parent to Child Example
Parent Component
parent.component.ts
export class ParentComponent {
employeeName = 'John';
}
parent.component.html
<app-child [name]="employeeName"></app-child>
Child Component
child.component.ts
import { Component, Input } from '@angular/core';
@Component({
selector: 'app-child',
template: `<h3>Employee Name: {{ name }}</h3>`
})
export class ChildComponent {
@Input() name!: string;
}
Output
Employee Name: John
Q: What happens if the user disables browser cache? How do you handle JWT tokens?
Answer:
JWT tokens should not rely on browser cache. Store tokens in Local Storage, Session Storage, or preferably HttpOnly Secure Cookies. If a token is removed or expired, implement a Refresh Token mechanism to generate a new Access Token without forcing the user to log in again. In production applications, HttpOnly cookies combined with refresh tokens are the most secure approach.
Q: Code First vs Database First in Entity Framework – Which is Faster?
There is no significant runtime performance difference between Code First and Database First in Entity Framework. Both generate the same SQL queries and use the same EF runtime.
Why?
Whether you use:
- Code First → Create C# classes first, then generate the database.
- Database First → Create the database first, then generate entity classes.
| Code First | Database First |
|---|---|
| Preferred for new projects | Preferred for existing databases |
| Easy migrations | Works well with legacy systems |
| Better source control | DB already designed by DBA |
| More developer-friendly | More DBA-friendly |
No comments:
Post a Comment