Skip to content

Commit 32227aa

Browse files
authored
Merge pull request #50 from manthanank/angular-interview-questions
new question and question related to standalone component added.
2 parents 365f3c2 + b141ea6 commit 32227aa

File tree

1 file changed

+89
-1
lines changed

1 file changed

+89
-1
lines changed

README.md

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,10 @@ You can download the PDF and Epub version of this repository from the latest run
326326
|273| [What is the benefit of Automatic Inlining of Fonts?](#what-is-the-benefit-of-automatic-inlining-of-fonts)|
327327
|274| [What is content projection?](#what-is-content-projection)|
328328
|275| [What is ng-content and its purpose?](#what-is-ng-content-and-its-purpose)|
329-
|276| [](#)|
329+
|276| [What is standalone component?](#what-is-standalone-component)|
330+
|277| [How to create a standalone component uing CLI command?](#how-to-create-a-standalone-component-uing-cli-command)
331+
|278| [How to create a standalone component manually?](#how-to-create-a-standalone-component-manually)
332+
|279| [](#)
330333

331334
1. ### What is Angular Framework?
332335

@@ -4602,5 +4605,90 @@ You can download the PDF and Epub version of this repository from the latest run
46024605
46034606
274. ### What is content projection?
46044607
Content projection is a pattern in which you insert, or project, the content you want to use inside another component.
4608+
4609+
**[⬆ Back to Top](#table-of-contents)**
4610+
46054611
275. ### What is ng-content and its purpose?
46064612
The ng-content is used to insert the content dynamically inside the component that helps to increase component reusability.
4613+
4614+
**[⬆ Back to Top](#table-of-contents)**
4615+
4616+
276. ### What is standalone component?
4617+
A standalone component is a type of component which is not part of any Angular module. It provides a simplified way to build Angular applications.
4618+
4619+
**[⬆ Back to Top](#table-of-contents)**
4620+
4621+
278. ### How to create a standalone component uing CLI command?
4622+
4623+
Generate standalone component using CLI command as shown below
4624+
```bash
4625+
ng generate component component-name --standalone
4626+
```
4627+
On running the command standalone component is created.
4628+
Here is the list of file created.
4629+
4630+
1. `component-name.component.ts`
4631+
2. `component-name.component.css`
4632+
3. `component-name.component.spec`
4633+
4. `component-name.component.html`
4634+
4635+
Next need to update `app.module.ts` as shown below.
4636+
4637+
```typescript
4638+
import { NgModule } from '@angular/core';
4639+
import { BrowserModule } from '@angular/platform-browser';
4640+
import { ComponentNameComponent } from './component-name/component-name.component';
4641+
4642+
@NgModule({
4643+
imports: [
4644+
BrowserModule,
4645+
ComponentNameComponent
4646+
],
4647+
declarations: [AppComponent],
4648+
bootstrap: [AppComponent],
4649+
})
4650+
export class AppModule {}
4651+
```
4652+
4653+
**[⬆ Back to Top](#table-of-contents)**
4654+
4655+
278. ### How to create a standalone component manually?
4656+
To make existing component to standalone, then add `standalone: true` in `component-name.component.ts`
4657+
as shown below
4658+
4659+
```typescript
4660+
import { CommonModule } from '@angular/common';
4661+
import { Component, OnInit } from '@angular/core';
4662+
4663+
@Component({
4664+
standalone: true,
4665+
imports: [CommonModule],
4666+
selector: 'app-standalone-component',
4667+
templateUrl: './standalone-component.component.html',
4668+
styleUrls: ['./standalone-component.component.css'],
4669+
})
4670+
export class ComponentNameComponent implements OnInit {
4671+
constructor() {}
4672+
4673+
ngOnInit() {}
4674+
}
4675+
```
4676+
Next need to update `app.module.ts` as shown below.
4677+
4678+
```typescript
4679+
import { NgModule } from '@angular/core';
4680+
import { BrowserModule } from '@angular/platform-browser';
4681+
import { ComponentNameComponent } from './component-name/component-name.component';
4682+
4683+
@NgModule({
4684+
imports: [
4685+
BrowserModule,
4686+
ComponentNameComponent
4687+
],
4688+
declarations: [AppComponent],
4689+
bootstrap: [AppComponent],
4690+
})
4691+
export class AppModule {}
4692+
```
4693+
4694+
**[⬆ Back to Top](#table-of-contents)**

0 commit comments

Comments
 (0)