Cookies concent notice

This site uses cookies from Google to deliver its services and to analyze traffic.
Learn more
Skip to main content
This site is no longer updated.Head to Angular.devHome
/

This is the archived documentation for Angular v17. Please visit angular.dev to see this page for the current version of Angular.

HostAttributeToken

Creates a token that can be used to inject static attributes of the host node.

      
      class HostAttributeToken {
  constructor(attributeName: string)
toString(): string }

Constructor

      
      constructor(attributeName: string)
    
Parameters
attributeName string

Methods

      
      toString(): string
    
Parameters

There are no parameters.

Returns

string

Usage notes

Injecting an attribute that is known to exist

      
      @Directive()
class MyDir {
  attr: string = inject(new HostAttributeToken('some-attr'));
}
    

Optionally injecting an attribute

      
      @Directive()
class MyDir {
  attr: string | null = inject(new HostAttributeToken('some-attr'), {optional: true});
}