Skip to content

Commit b407157

Browse files
JeanMechethePunderWoman
authored andcommitted
refactor(core): Deprecate the structural directives ngIf/ngFor/ngSwitch. (#60492)
Note: This is not a deprecation of structural directives, this only about `ngIf`/`ngFor`/`ngSwitch`. DEPRECATED: `ngIf`/`ngFor`/`ngSwitch` are deprecated. Use the control flow blocks instead (`@for`/`@if`/`@switch`). PR Close #60492
1 parent 152261c commit b407157

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

goldens/public-api/common/index.api.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ export class NgComponentOutlet<T = any> implements OnChanges, DoCheck, OnDestroy
516516
static ɵfac: i0.ɵɵFactoryDeclaration<NgComponentOutlet<any>, never>;
517517
}
518518

519-
// @public
519+
// @public @deprecated
520520
class NgForOf<T, U extends NgIterable<T> = NgIterable<T>> implements DoCheck {
521521
constructor(_viewContainer: ViewContainerRef, _template: TemplateRef<NgForOfContext<T, U>>, _differs: IterableDiffers);
522522
ngDoCheck(): void;
@@ -534,7 +534,7 @@ class NgForOf<T, U extends NgIterable<T> = NgIterable<T>> implements DoCheck {
534534
export { NgForOf as NgFor }
535535
export { NgForOf }
536536

537-
// @public (undocumented)
537+
// @public @deprecated (undocumented)
538538
export class NgForOfContext<T, U extends NgIterable<T> = NgIterable<T>> {
539539
$implicit: T;
540540
constructor(
@@ -555,7 +555,7 @@ export class NgForOfContext<T, U extends NgIterable<T> = NgIterable<T>> {
555555
get odd(): boolean;
556556
}
557557

558-
// @public
558+
// @public @deprecated
559559
export class NgIf<T = unknown> {
560560
constructor(_viewContainer: ViewContainerRef, templateRef: TemplateRef<NgIfContext<T>>);
561561
set ngIf(condition: T);
@@ -682,7 +682,7 @@ export class NgStyle implements DoCheck {
682682
static ɵfac: i0.ɵɵFactoryDeclaration<NgStyle, never>;
683683
}
684684

685-
// @public
685+
// @public @deprecated
686686
export class NgSwitch {
687687
// (undocumented)
688688
set ngSwitch(newValue: any);

packages/common/src/directives/ng_for_of.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import {RuntimeErrorCode} from '../errors';
2626

2727
/**
2828
* @publicApi
29+
*
30+
* @deprecated The `ngFor` directive is deprecated. Use the `@for` block instead.
2931
*/
3032
export class NgForOfContext<T, U extends NgIterable<T> = NgIterable<T>> {
3133
constructor(
@@ -164,6 +166,8 @@ export class NgForOfContext<T, U extends NgIterable<T> = NgIterable<T>> {
164166
* @see [Structural Directives](guide/directives/structural-directives)
165167
* @ngModule CommonModule
166168
* @publicApi
169+
*
170+
* @deprecated Use the @for block instead. Intent to remove in v22
167171
*/
168172
@Directive({
169173
selector: '[ngFor][ngForOf]',

packages/common/src/directives/ng_if.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ import {RuntimeErrorCode} from '../errors';
156156
*
157157
* @ngModule CommonModule
158158
* @publicApi
159+
*
160+
* @deprecated Use the @if block instead. Intent to remove in v22
159161
*/
160162
@Directive({
161163
selector: '[ngIf]',

packages/common/src/directives/ng_switch.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export class SwitchView {
111111
* @see {@link NgSwitchDefault}
112112
* @see [Structural Directives](guide/directives/structural-directives)
113113
*
114+
* @deprecated Use the @switch block instead. Intent to remove in v22
114115
*/
115116
@Directive({
116117
selector: '[ngSwitch]',
@@ -196,6 +197,7 @@ export class NgSwitch {
196197
* @see {@link NgSwitch}
197198
* @see {@link NgSwitchDefault}
198199
*
200+
* @deprecated Use the @case block within a @switch block instead. Intent to remove in v22
199201
*/
200202
@Directive({
201203
selector: '[ngSwitchCase]',
@@ -242,6 +244,7 @@ export class NgSwitchCase implements DoCheck {
242244
* @see {@link NgSwitch}
243245
* @see {@link NgSwitchCase}
244246
*
247+
* @deprecated Use the @default block within a @switch block instead. Intent to remove in v22
245248
*/
246249
@Directive({
247250
selector: '[ngSwitchDefault]',

0 commit comments

Comments
 (0)