FrontEndTech
  • Introduction
  • ReactJS
    • Ecosystem
    • Refactor Using Functional Decomposition and Reducer Composition
  • AngularJS
    • installation
    • File structure
    • CLI
      • ng g
    • Fundamentals
      • Component
        • Lifecycle
        • Template
      • Decorations
      • Service
      • Pipe
      • Directives
        • NgClass
        • NgStyle
        • NgModel
        • Customized Attribute Directives
        • NgIf
        • NgFor
        • NgSwitch
        • NgForm
        • Customized Structural Directives
      • Module
        • Routing
    • Bindings
      • Property Binding
      • Event Binding
      • Data Binding
      • Attribute Binding
      • Class Binding
      • Style Binding
    • Forms
      • Reactive Form
      • Reactive vs Template
    • build
Powered by GitBook
On this page

Was this helpful?

  1. AngularJS
  2. Bindings

Attribute Binding

You must use attribute binding when there is no element property to bind.

e.g. ARIA, SVG, and table span attributes are pure attributes.

When you write something like this

<tr><td colspan="{{1 + 1}}">Three-Four</td></tr>

you get this error

Template parse errors:
Can't bind to 'colspan' since it isn't a known native property

the <td> element does not have a colspan property. It has the "colspan" attribute, but interpolation and property binding can set only properties, not attributes.

Instead, you have to write like this

<tr><td [attr.colspan]="1 + 1">One-Two</td></tr>
PreviousData BindingNextClass Binding

Last updated 5 years ago

Was this helpful?