Angular-RU SDK
  • Getting Started
    • Introduction
  • CDK
    • @angular-ru/cdk/typings
    • @angular-ru/cdk/number
    • @angular-ru/cdk/string
    • @angular-ru/cdk/date
    • @angular-ru/cdk/array
    • @angular-ru/cdk/object
    • @angular-ru/cdk/regexp
    • @angular-ru/cdk/function
    • @angular-ru/cdk/runtime
    • @angular-ru/cdk/ivy
    • @angular-ru/cdk/utils
    • @angular-ru/cdk/class-transformer
    • @angular-ru/cdk/validators
    • @angular-ru/cdk/directives
    • @angular-ru/cdk/decorators
    • @angular-ru/cdk/pipes
    • @angular-ru/cdk/rxjs
    • @angular-ru/cdk/animations
    • @angular-ru/cdk/zone.js
    • @angular-ru/cdk/webworker
    • @angular-ru/cdk/node.js
    • @angular-ru/cdk/flex-layout
    • @angular-ru/cdk/http
    • @angular-ru/cdk/logger
    • @angular-ru/cdk/stream
    • @angular-ru/cdk/tooltip
    • @angular-ru/cdk/virtual-table
    • @angular-ru/cdk/big-decimal
  • NGXS
    • Introduction
    • @StateRepository
    • @DataAction
    • @Computed
    • @Persistence
    • Entity state adapter
    • Unit Testing
    • Lifecycle
    • Immutability
    • Extension API
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. CDK

@angular-ru/cdk/decorators

  • AttributeBoolean

import { AttributeBoolean } from '@angular-ru/cdk/decorators';
import { InputBoolean } from '@angular-ru/cdk/typings';

@Component({
    selector: 'child-component',
    template: ''
})
class ChildComponent {
    @AttributeBoolean() @Input() public prop1: InputBoolean; // === true
    @Input() public prop2: InputBoolean; // === '', while ('' == false)
    @AttributeBoolean() @Input() public prop3: InputBoolean; // === false
    @AttributeBoolean() @Input() public prop4: InputBoolean; // === true
    @AttributeBoolean() @Input() public prop5: InputBoolean; // === true
    @AttributeBoolean() @Input() public prop6: InputBoolean; // === false

    private _prop7: string;
    @AttributeBoolean()
    @Input()
    public set prop7(value: InputBoolean) {
        this._prop6 = `prop7: ${value}`;
    }

    public get prop7(): InputBoolean {
        // === 'prop7: true - from getter'
        return this._prop7 ? `${this._prop7} - from getter` : undefined;
    }

    // order doesn't matter in all cases
    public prop8Calls: boolean[] = []; // === [true]
    @AttributeBoolean()
    @Input()
    public set prop8(value: InputBoolean) {
        this.hookCalls.push(value as boolean);
    }

    @AttributeBoolean() @Input() public prop9: InputBoolean; // === false
}

@Component({
    selector: 'host-component',
    template: `
        <child-component
            prop1
            prop2
            prop7
            prop8
            prop9="false"
            [prop3]="falseString"
            [prop4]="someAnotherTruthy"
            [prop5]="emptyString"
            [prop6]="someAnotherFalsy"
        ></child-component>
    `
})
class HostComponent {
    public falseString: string = 'false';
    public someAnotherTruthy: any = {};
    public emptyString: string = '';
    public someAnotherFalsy: any = null;
}
  • BoundClass

@Injectable()
class B {
    public b: string = '2';
}

@BoundClass
@Injectable()
class A {
    public a: string = '1';

    constructor(public readonly b: B) {}

    public getA() {
        return this;
    }
}

TestBed.configureTestingModule({ providers: [A, B] });

const a = TestBed.inject(A);
const { getA } = a;

expect(a).toEqual({ a: '1', b: { b: '2' } });
expect(getA()).toEqual({ a: '1', b: { b: '2' } });
expect(getA() === a).toBeTruthy();
Previous@angular-ru/cdk/directivesNext@angular-ru/cdk/pipes

Last updated 3 years ago

Was this helpful?