Skip to content

Commit

Permalink
docs: Add Stackblitz examples in README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
manthanank committed Oct 8, 2024
1 parent 90afb3b commit 4eeae38
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,8 @@ import { DatePipe } from '@angular/common';
export class AppModule {}
```

[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-fobnad?file=src%2Fapp%2Fapp.component.ts)

### Uppercase Pipe

The `uppercase` pipe is used to transform a string to uppercase.
Expand All @@ -1997,6 +1999,8 @@ export class AppComponent {
}
```

[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-hlmoxp?file=src%2Fapp%2Fapp.component.ts)

### Lowercase Pipe

The `lowercase` pipe is used to transform a string to lowercase.
Expand All @@ -2018,6 +2022,8 @@ export class AppComponent {
}
```

[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-6gcdgx?file=src%2Fapp%2Fapp.component.ts)

### Currency Pipe

The `currency` pipe is used to format a number as currency using the locale rules specified in the application.
Expand Down Expand Up @@ -2064,6 +2070,8 @@ import { CurrencyPipe } from '@angular/common';
export class AppModule {}
```

[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-3fhhzz?file=src%2Fapp%2Fapp.component.ts)

### Percent Pipe

The `percent` pipe is used to format a number as a percentage.
Expand Down Expand Up @@ -2111,6 +2119,8 @@ import { PercentPipe } from '@angular/common';
export class AppModule {}
```

[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-tccybj?file=src%2Fapp%2Fapp.component.ts)

### Slice Pipe

The `slice` pipe is used to create a new array or string containing a subset of the elements of the input array or string.
Expand All @@ -2119,6 +2129,8 @@ The `slice` pipe is used to create a new array or string containing a subset of
<p>{{ ['apple', 'banana', 'orange', 'mango'] | slice:1:3 }}</p>
```

[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-q88gmm?file=src%2Fapp%2Fapp.component.ts)

### Decimal/number Pipe

The `number` pipe is used to format a number as text. It can be used to format a number as a percentage, currency, or decimal number.
Expand All @@ -2127,6 +2139,8 @@ The `number` pipe is used to format a number as text. It can be used to format a
<p>{{ 123456.78 | number:'3.2-3' }}</p>
```

[Stackblitz Example](https://stackblitz.com/edit/angular-ivy-7cwk1u?file=src%2Fapp%2Fapp.component.ts)

### JSON Pipe

The `json` pipe is used to transform a JavaScript object into a JSON string.
Expand All @@ -2135,6 +2149,22 @@ The `json` pipe is used to transform a JavaScript object into a JSON string.
<p>{{data | json}}</p>
```

```typescript
import { Component } from '@angular/core';

@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})

export class AppComponent {
data = { name: 'Manthan Ank', age: 25 };
}
```

[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-jgc252?file=src%2Fmain.ts)

### Async Pipe

The `async` pipe is used to subscribe to an Observable or Promise and return the latest value it has emitted.
Expand Down Expand Up @@ -2185,6 +2215,8 @@ export class ExampleComponent {
}
```

[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-iatcbn?file=src%2Fmain.ts)

### Impure Pipes

By default, Angular pipes are pure, meaning they are stateless and do not change unless the input value changes. However, you can create impure pipes by setting the pure property to false in the @Pipe decorator.
Expand All @@ -2204,6 +2236,40 @@ export class ImpurePipe implements PipeTransform {
}
```

```html
<p>{{ data | impurePipe }}</p>
```

```typescript
import { Component } from '@angular/core';

@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})

export class AppComponent {
data = 'Hello, world!';
}
```

```typescript
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';

import { AppComponent } from './app.component';

@NgModule({
imports: [BrowserModule, FormsModule],
declarations: [AppComponent, ImpurePipe],
bootstrap: [AppComponent],
})
export class AppModule {}
```

[Stackblitz Example](https://stackblitz.com/edit/stackblitz-starters-xy3hhp?file=src%2Fmain.ts)

[Back to top⤴️](#table-of-contents)

## Decorators
Expand Down

0 comments on commit 4eeae38

Please sign in to comment.