17.0.2 • Published 3 days ago

@opi_pib/ngx-utility v17.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 days ago

ngx-utility

DOM

renderMarkup

Render html markup, if html contains large text nodes they will be splitted to separate spans based on maxChunkLength value

const markup = `1234567`;
const parent = document.createElement("div");
const maxChunkLength = 2;

const callback = () => {
	console.log("done");
};

renderMarkup({ markup, parent, maxChunkLength }, callback); // will render <span>12</span><span>34</span><span>56</span><span>7</span>

window

InjectionToken which is an abstraction over global window object

@Injectable({
	providedIn: "root",
})
export class MyService {
	constructor(@Inject(WINDOW) private window: Window) {}
}

Forms

FormConnector

Set control as child of other form group

@Component()
export class ChildFormComponent {
	constructor(private controlContainer: ControlContainer, private registerUserDetailsFormService: RegisterUserDetailsFormService) {
		this.childForm = new FormGroup({});
		FormConnector.connectControlWithParent(controlContainer, "childName", this.childForm);
	}
}

FormControlsOf

Transform type into FormControls

type User = {
	name: string;
};

type UserFormControls = FormControlsOf<User>;

Http

RestQuery

@Injectable({
	providedIn: "root",
})
export class RestUserGetService extends RestQuery {
	constructor(private httpClient: HttpClient) {
		super();
	}

	getUser$(userId: UserId): Observable<User> {
		return this.query$(this.httpClient.get<UserDto>(`${environment.restUri}/user/${userId.id}`)).pipe(map((userDto) => User.fromDto(userDto)));
	}
}

@Component({
	selector: "app-user-page",
	template: `
		<ng-container *ngIf="user$ | async as user">
			{{ user.name }}
		</ng-container>

		<mat-progress-spinner *ngIf="isProcessing$ | async" mode="indeterminate" color="primary"></mat-progress-spinner>
	`,
	styleUrls: ["./user-page.component.scss"],
	changeDetection: ChangeDetectionStrategy.OnPush,
})
export class UserPageComponent {
	user$: Observable<User>;

	isProcessing$: Observable<boolean> = RestQuery.isProcessingAny$([this.restUserGetService.isProcessing$()]);

	constructor(private restUserGetService: RestUserGetService) {
		this.user$ = this.restUserGetService.getUser$(
			UserId.create({
				id: "00000000-aaaa-dddd-ffff-000000000000",
			})
		);
	}
}

Schedulers

Enter NgZone

Enter NgZone inside observable

of(1)
	.pipe(observeOn(enterNgZone(this.ngZone)))
	.subscribe();

Leave NgZone

Leave NgZone inside observable

of(1)
	.pipe(observeOn(leaveNgZone(this.ngZone)))
	.subscribe();

Wcag

forRoot

Detectects focus source and add class to body (https://material.angular.io/cdk/a11y/overview#cdkmonitorelementfocus-and-cdkmonitorsubtreefocus)

Detectects high contrast mode and add 'hc-active' to body

@NgModule({
  ...
	imports: [
    ...
		WcagModule.forRoot(),
	],
})
export class AppModule {}
17.0.2

3 days ago

17.0.1

2 months ago

17.0.0

6 months ago

16.0.2

7 months ago

16.0.1

7 months ago

16.0.3

7 months ago

16.0.0

12 months ago

15.1.5

1 year ago

15.1.1

1 year ago

15.0.2

1 year ago

15.1.2

1 year ago

15.1.0

1 year ago

15.1.3

1 year ago

15.1.4

1 year ago

15.0.0

1 year ago

15.0.1

1 year ago

14.0.2

2 years ago

14.0.1

2 years ago

14.0.0

2 years ago