Skip to content

Commit 52abc6e

Browse files
authored
Merge pull request #39 from manthanank/new-changes
feat: added signals, angular signals, destroyref
2 parents 605c576 + b0a8e78 commit 52abc6e

File tree

1 file changed

+73
-1
lines changed

1 file changed

+73
-1
lines changed

README.md

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
- [OnDestroy](#ondestroy)
4747
- [Forms](#forms)
4848
- [Signals](#signals)
49+
- [Angular Signals](#angular-signals)
50+
- [Destroy Ref](#destroy-ref)
4951
- [Http](#http)
5052
- [Module](#module)
5153
- [Router](#router)
@@ -1560,7 +1562,77 @@ FormArrays
15601562
15611563
## Signals
15621564
1563-
A signal is a wrapper around a value that can notify interested consumers when that value changes. Signals can contain any value, from simple primitives to complex data structures.
1565+
Signals serve as wrappers around values, offering the ability to notify interested consumers whenever the encapsulated value undergoes a change. These signals can accommodate a wide range of values, encompassing both basic primitives and intricate data structures.
1566+
1567+
## Angular Signals
1568+
1569+
Angular Signals is a powerful system that provides detailed monitoring of state usage within an application, enabling the framework to efficiently optimize rendering updates.
1570+
1571+
```typescript
1572+
import { Component, OnInit } from '@angular/core';
1573+
import { signal } from '@angular/cdk/platform-browser';
1574+
1575+
@Component({
1576+
selector: 'my-app',
1577+
templateUrl: './app.component.html',
1578+
styleUrls: ['./app.component.css']
1579+
})
1580+
export class AppComponent implements OnInit {
1581+
1582+
count = signal(0);
1583+
1584+
constructor() { }
1585+
1586+
ngOnInit() {
1587+
this.count.subscribe(value => {
1588+
console.log('Count changed to', value);
1589+
});
1590+
}
1591+
1592+
incrementCount() {
1593+
this.count.value++;
1594+
}
1595+
1596+
}
1597+
```
1598+
1599+
```html
1600+
<h1>Angular Signals Example</h1>
1601+
1602+
<button (click)="incrementCount()">Increment Count</button>
1603+
1604+
<p>Count: {{ count }}</p>
1605+
```
1606+
1607+
## Destroy Ref
1608+
1609+
DestroyRef is a new provider in Angular 16 that allows you to register destroy callbacks for a specific lifecycle scope. This feature is applicable to components, directives, pipes, embedded views, and instances of EnvironmentInjector.
1610+
1611+
```typescript
1612+
import { Component, OnInit, OnDestroy } from '@angular/core';
1613+
import { DestroyRef } from '@angular/core/testing';
1614+
1615+
@Component({
1616+
selector: 'my-component',
1617+
templateUrl: './my-component.component.html',
1618+
styleUrls: ['./my-component.component.css']
1619+
})
1620+
export class MyComponent implements OnInit, OnDestroy {
1621+
1622+
constructor(private destroyRef: DestroyRef) {}
1623+
1624+
ngOnInit() {
1625+
}
1626+
1627+
ngOnDestroy() {
1628+
// Register a destroy callback with the DestroyRef provider.
1629+
this.destroyRef.register(() => {
1630+
// Do any cleanup tasks here.
1631+
});
1632+
}
1633+
1634+
}
1635+
```
15641636
15651637
## HTTP
15661638

0 commit comments

Comments
 (0)