3.0.0 • Published 6 months ago

@ngx-toolset/template-type-checker v3.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@ngx-toolset/template-type-checker

Build & Release npm version License: MIT npm.io

Table of Contents

Features

  • Possibility to validate object's class instance type in HTML template

Installation

NPM

npm install @ngx-toolset/template-type-checker --save

Choose the version corresponding to your Angular version:

Angular@ngx-toolset/template-type-checker
14.x.x>=0.0.1 <=1.0.0-rc.9
15.x.x1.0.0-rc.10
16.x.x>=1.0.0-rc.11 <=2.x.x
17.x.x3.0.0

Usage

Import

Import the TypeCheckerPipe in the component(s) you would like to use it:

import { Component } from '@angular/core';
import { TypeCheckerPipe } from '@ngx-toolset/template-type-checker';

@Component({
  selector: 'app-sample',
  templateUrl: 'sample.component.html',
  styleUrls: ['sample.component.scss'],
  standalone: true,
  imports: [TypeCheckerPipe],
})
export class SampleComponent {}

TS Example

import { Component } from '@angular/core';
import { TypeCheckerPipe } from '@ngx-toolset/template-type-checker';

class ClassA {}

class ClassB {}

@Component({
  selector: 'app-sample',
  templateUrl: './sample.component.html',
  styleUrls: ['./sample.component.scss'],
  standalone: true,
  imports: [TypeCheckerPipe],
})
export class SampleComponent {
  public classA: typeof ClassA;
  public classB: typeof ClassB;
  public sampleObject: ClassA;

  public constructor() {
    this.classA = ClassA;
    this.classB = ClassB;
    this.sampleObject = new ClassA();
  }
}

HTML Example

<!-- TypeCheckerPipe returns object of type ClassA -> ngIf evaluates to truthy value -->
<div *ngIf="sampleObject | typeChecker:classA">
  This div will be rendered.
</div>

<!-- TypeCheckerPipe returns undefined -> ngIf evaluates to falsy value -->
<div *ngIf="sampleObject | typeChecker:classB">
  This div will not be rendered.
</div>
1.0.1

9 months ago

1.0.0

9 months ago

3.0.0

6 months ago

1.0.0-rc.11

9 months ago

2.0.0

6 months ago

1.0.0-rc.10

1 year ago

1.0.0-rc.9

1 year ago

1.0.0-rc.8

2 years ago

1.0.0-rc.7

2 years ago

1.0.0-rc.6

2 years ago

1.0.0-rc.5

2 years ago

1.0.0-rc.4

2 years ago

1.0.0-rc.3

2 years ago

1.0.0-rc.2

2 years ago

1.0.0-rc.1

2 years ago

1.0.0-rc.0

2 years ago

1.0.0-beta.2

2 years ago

1.0.0-beta.1

2 years ago

0.0.1

2 years ago