Home > Software engineering >  binding Angular assigning from Square Brackets (value including ="[...]")
binding Angular assigning from Square Brackets (value including ="[...]")

Time:02-01

Sorry for this silly question!

I found this binding as:

 <ng-template [ngxPermissionsExcept]="['JOHNY']">
     ....
 </ng-template>

This other:

<mat-list-item [routerLink]="[child.route]">

A Partner told me that I need to use Square Brackets in order to avoid that Style:

        [formControlName]="component.name"
        [placeholder]="component.label"

Here isn't The angular brackets [] () {} what they bind and when to use which

What is the name for this assignation style: ="[...]">?

When is necessary to use it?

CodePudding user response:

{{expression}} (type: Interpolation) and [target]="expression" (type: Property Attribute) are One-way Data Direction from data source to view target.

(target)="statement" (type: Event) is One-way Data Direction from view target to data source.

[(target)]="expression" (type: Two-way) is Two-way Data Direction

CodePudding user response:

The square bracket notation like [...]="[...]" is used when the corresponding @Input() definition accepts an array type as argument.

In your case

  1. [routerLink]="[child.route]"

    • The corresponding @Input() definition accepts arguments of type any[]|string|null|undefined and your specific usage is of type any[].
    • You can refer here for a more extended use case of [routerLink] binding.
  2. [ngxPermissionsExcept]="['JOHNY']"

    • The corresponding @Input() definition accepts arguments of type String | String[] and your specific usage is of type String[].
    • You can refer here for other use cases of [ngxPermissionsExcept] binding.
  •  Tags:  
  • Related