Browse Source

update: control flow syntax

pull/24196/head
sumeyye 2 months ago
parent
commit
4492a14e46
  1. 2
      docs/en/docs-nav.json
  2. 23
      docs/en/framework/ui/angular/component-replacement.md
  3. 16
      docs/en/framework/ui/angular/form-validation.md
  4. 24
      docs/en/framework/ui/angular/lazy-load-service.md
  5. 41
      docs/en/framework/ui/angular/permission-management-component-replacement.md
  6. 4
      docs/en/framework/ui/angular/theming.md
  7. 36
      docs/en/framework/ui/angular/track-by-service.md
  8. 2
      docs/en/tutorials/book-store/part-03.md

2
docs/en/docs-nav.json

@ -1641,7 +1641,7 @@
"path": "framework/ui/angular/list-service.md"
},
{
"text": "Easy *ngFor trackBy",
"text": "Easy @for() track",
"path": "framework/ui/angular/track-by-service.md"
},
{

23
docs/en/framework/ui/angular/component-replacement.md

@ -584,8 +584,8 @@ Open the generated `nav-items.component.html` in `src/app/nav-items` folder and
class="bg-transparent border-0 text-white"
/>
<li class="nav-item d-flex align-items-center">
@if ((dropdownLanguages$ | async)?.length > 0) {
<div
*ngIf="(dropdownLanguages$ | async)?.length > 0"
class="dropdown"
ngbDropdown
#languageDropdown="ngbDropdown"
@ -618,15 +618,11 @@ Open the generated `nav-items.component.html` in `src/app/nav-items` folder and
}
</div>
</div>
}
</li>
<li class="nav-item d-flex align-items-center">
<ng-template #loginBtn>
<a role="button" class="nav-link pointer" (click)="navigateToLogin()"
>{%{{{ 'AbpAccount::Login' | abpLocalization }}}%}</a
>
</ng-template>
@if ((currentUser$ | async)?.isAuthenticated) {
<div
*ngIf="(currentUser$ | async)?.isAuthenticated; else loginBtn"
ngbDropdown
class="dropdown"
#currentUserDropdown="ngbDropdown"
@ -642,9 +638,9 @@ Open the generated `nav-items.component.html` in `src/app/nav-items` folder and
aria-haspopup="true"
aria-expanded="false"
>
<small *ngIf="(selectedTenant$ | async)?.name as tenantName"
><i>{%{{{ tenantName }}}%}</i>\</small
>
@if ((selectedTenant$ | async)?.name as tenantName) {
<small><i>{%{{{ tenantName }}}%}</i>\</small>
}
<strong>{%{{{ (currentUser$ | async)?.userName }}}%}</strong>
</a>
<div
@ -662,6 +658,13 @@ Open the generated `nav-items.component.html` in `src/app/nav-items` folder and
>
</div>
</div>
} @else {
<ng-template #loginBtn>
<a role="button" class="nav-link pointer" (click)="navigateToLogin()">
{%{{{ 'AbpAccount::Login' | abpLocalization }}}%}
</a>
</ng-template>
}
</li>
</ul>
```

16
docs/en/framework/ui/angular/form-validation.md

@ -146,12 +146,12 @@ import { ChangeDetectionStrategy, Component } from "@angular/core";
selector: "app-validation-error",
imports:[CommonModule, LocalizationPipe],
template: `
@for (error of abpErrors; track $index)
<div
class="font-weight-bold font-italic px-1 invalid-feedback"
>
{%{{{ error.message | abpLocalization: error.interpoliteParams }}}%}
</div>
@for (error of abpErrors; track $index){
<div
class="font-weight-bold font-italic px-1 invalid-feedback"
>
{%{{{ error.message | abpLocalization: error.interpoliteParams }}}%}
</div>
}
`,
changeDetection: ChangeDetectionStrategy.OnPush,
@ -251,7 +251,7 @@ buildForm() {
<a ngbNavLink>{%{{ 'AbpIdentity::UserInformations' | abpLocalization }}%}</a>
<ng-template ngbNavContent>
<!-- Automatically displays all entity fields and their validation -->
<abp-extensible-form [selectedRecord]="selected"></abp-extensible-form>
<abp-extensible-form [selectedRecord]="selected" />
</ng-template>
</li>
@ -264,7 +264,7 @@ buildForm() {
<abp-checkbox
[formControl]="roleGroup.controls[roles[i].name]"
[label]="roles[i].name"
></abp-checkbox>
/>
</div>
}
</ng-template>

24
docs/en/framework/ui/angular/lazy-load-service.md

@ -44,10 +44,13 @@ The first parameter of `load` method expects a `LoadingStrategy`. If you pass a
```js
import { LazyLoadService, LOADING_STRATEGY } from '@abp/ng.core';
import { inject } from '@angular/core';
import { AsyncPipe } from '@angular/common';
@Component({
template: `
<some-component *ngIf="libraryLoaded$ | async"></some-component>
@if (libraryLoaded$ | async) {
<some-component/>
}
`
})
class DemoComponent {
@ -59,7 +62,7 @@ class DemoComponent {
}
```
The `load` method returns an observable to which you can subscibe in your component or with an `async` pipe. In the example above, the `NgIf` directive will render `<some-component>` only **if the script gets successfully loaded or is already loaded before**.
The `load` method returns an observable to which you can subscibe in your component or with an `async` pipe. In the example above, the `@if(...)` directive will render `<some-component>` only **if the script gets successfully loaded or is already loaded before**.
> You can subscribe multiple times in your template with `async` pipe. The Scripts will only be loaded once.
@ -74,10 +77,13 @@ If you pass a `StyleLoadingStrategy` instance as the first parameter of `load` m
```js
import { LazyLoadService, LOADING_STRATEGY } from '@abp/ng.core';
import { inject } from '@angular/core';
import { AsyncPipe } from '@angular/common';
@Component({
template: `
<some-component *ngIf="stylesLoaded$ | async"></some-component>
@if (stylesLoaded$ | async) {
<some-component/>
}
`
})
class DemoComponent {
@ -89,7 +95,7 @@ class DemoComponent {
}
```
The `load` method returns an observable to which you can subscibe in your component or with an `AsyncPipe`. In the example above, the `NgIf` directive will render `<some-component>` only **if the style gets successfully loaded or is already loaded before**.
The `load` method returns an observable to which you can subscibe in your component or with an `AsyncPipe`. In the example above, the `@if(...)` directive will render `<some-component>` only **if the style gets successfully loaded or is already loaded before**.
> You can subscribe multiple times in your template with `async` pipe. The styles will only be loaded once.
@ -126,10 +132,13 @@ A common usecase is **loading multiple scripts and/or styles before using a feat
import { LazyLoadService, LOADING_STRATEGY } from '@abp/ng.core';
import { forkJoin } from 'rxjs';
import { inject } from '@angular/core';
import { AsyncPipe } from '@angular/common';
@Component({
template: `
<some-component *ngIf="scriptsAndStylesLoaded$ | async"></some-component>
@if (scriptsAndStylesLoaded$ | async) {
<some-component />
}
`
})
class DemoComponent {
@ -168,10 +177,13 @@ Another frequent usecase is **loading dependent scripts in order**:
import { LazyLoadService, LOADING_STRATEGY } from '@abp/ng.core';
import { concat } from 'rxjs';
import { inject } from '@angular/core';
import { AsyncPipe } from '@angular/common';
@Component({
template: `
<some-component *ngIf="scriptsLoaded$ | async"></some-component>
@if (scriptsLoaded$ | async) {
<some-component />
}
`
})
class DemoComponent {

41
docs/en/framework/ui/angular/permission-management-component-replacement.md

@ -334,7 +334,7 @@ Open the generated `permission-management.component.html` in `src/app/permission
```html
<abp-modal [visible]="isVisible" (visibleChange)="onVisibleChange($event)" [busy]="modalBusy">
<ng-container *ngIf="data.entityDisplayName">
@if (data.entityDisplayName) {
<ng-template #abpHeader>
<h4>
{%{{{ 'AbpPermissionManagement::Permissions' | abpLocalization }}}%} -
@ -362,17 +362,18 @@ Open the generated `permission-management.component.html` in `src/app/permission
<ul class="nav nav-pills flex-column">
@for (group of data.groups; track group.name) {
<li class="nav-item">
<a
*ngIf="{ assignedCount: getAssignedCount(group.name) } as count"
class="nav-link pointer"
[class.active]="selectedGroup?.name === group?.name"
(click)="onChangeGroup(group)"
>
<div [class.font-weight-bold]="count.assignedCount">
{%{{{ group?.displayName }}}%}
<span>({%{{{ count.assignedCount }}}%})</span>
</div>
</a>
@if ({ assignedCount: getAssignedCount(group.name) } as count) {
<a
class="nav-link pointer"
[class.active]="selectedGroup?.name === group?.name"
(click)="onChangeGroup(group)"
>
<div [class.font-weight-bold]="count.assignedCount">
{%{{{ group?.displayName }}}%}
<span>({%{{{ count.assignedCount }}}%})</span>
</div>
</a>
}
</li>
}
</ul>
@ -413,15 +414,15 @@ Open the generated `permission-management.component.html` in `src/app/permission
class="custom-control-label"
[attr.for]="permission.name"
(click)="onClickCheckbox(permission, permissionCheckbox.value)"
>{%{{{ permission.displayName }}}%}
<ng-container *ngIf="!hideBadges">
>
{%{{{ permission.displayName }}}%}
@if (!hideBadges) {
@for (provider of permission.grantedProviders; track provider.providerKey) {
<span
class="badge badge-light"
>{%{{{ provider.providerName }}}%}: {%{{{ provider.providerKey }}}%}</span
>
<span class="badge badge-light">
{%{{{ provider.providerName }}}%}: {%{{{ provider.providerKey }}}%}
</span>
}
</ng-container>
}
</label>
</div>
}
@ -437,7 +438,7 @@ Open the generated `permission-management.component.html` in `src/app/permission
'AbpIdentity::Save' | abpLocalization
}}}%}</abp-button>
</ng-template>
</ng-container>
}
</abp-modal>
```

4
docs/en/framework/ui/angular/theming.md

@ -238,8 +238,10 @@ import { Router } from '@angular/router';
selector: 'abp-current-user-test',
template: `
<a class="dropdown-item pointer" (click)="data.action()">
<i *ngIf="data.textTemplate.icon" [class]="data.textTemplate.icon"></i>
@if (data.textTemplate.icon){
<i [class]="data.textTemplate.icon"></i>
{%{{{ data.textTemplate.text | abpLocalization }}}%}
}
</a>
`,
})

36
docs/en/framework/ui/angular/track-by-service.md

@ -5,7 +5,7 @@
}
```
# Easy *ngFor trackBy
# Easy @for() track
`TrackByService` is a utility service to provide an easy implementation for one of the most frequent needs in Angular templates: `TrackByFunction`. Please see [this page in Angular docs](https://angular.dev/guide/templates/control-flow) for its purpose.
@ -54,8 +54,9 @@ You can use `by` to get a `TrackByFunction` that tracks the iterated object base
```html
<!-- template of DemoComponent -->
<div *ngFor="let item of list; trackBy: track.by('id')">{%{{{ item.name }}}%}</div>
@for (item of list; track: track.by('id')) {
<div>{%{{{ item.name }}}%}</div>
}
```
@ -67,11 +68,11 @@ import { trackBy } from "@abp/ng.core";
@Component({
template: `
<div
*ngFor="let item of list; trackBy: trackById"
>
{%{{{ item.name }}}%}
</div>
@for (item of list; track: trackById) {
<div>
{%{{{ item.name }}}%}
</div>
}
`,
})
class DemoComponent {
@ -89,12 +90,11 @@ You can use `byDeep` to get a `TrackByFunction` that tracks the iterated object
```html
<!-- template of DemoComponent -->
<div
*ngFor="let item of list; trackBy: track.byDeep('tenant', 'account', 'id')"
>
{%{{{ item.tenant.name }}}%}
</div>
@for (item of list; track: track.byDeep('tenant', 'account', 'id')) {
<div >
{%{{{ item.tenant.name }}}%}
</div>
}
```
@ -106,11 +106,11 @@ import { trackByDeep } from "@abp/ng.core";
@Component({
template: `
<div
*ngFor="let item of list; trackBy: trackByTenantAccountId"
>
{%{{{ item.name }}}%}
@for (item of list; track: trackByTenantAccountId) {
<div>
{%{{{ item.name }}}%}
</div>
}
`,
})
class DemoComponent {

2
docs/en/tutorials/book-store/part-03.md

@ -742,7 +742,7 @@ export class BookComponent implements OnInit {
* Imported `FormGroup`, `FormBuilder` and `Validators` from `@angular/forms`.
* Added a `form: FormGroup` property.
* Added a `bookTypes` property as a list of `BookType` enum members. That will be used in form options.
* Injected the `FormBuilder` with the inject function. [FormBuilder](https://angular.io/api/forms/FormBuilder) provides convenient methods for generating form controls. It reduces the amount of boilerplate that is needed to build complex forms.
* Injected the `FormBuilder` with the inject function. [FormBuilder](https://angular.dev/api/forms/FormBuilder) provides convenient methods for generating form controls. It reduces the amount of boilerplate that is needed to build complex forms.
* Added a `buildForm` method at the end of the file and executed the `buildForm()` in the `createBook` method.
* Added a `save` method.

Loading…
Cancel
Save