Skip to content

Unknown property error improvement when an @Attribute is used #45772

Closed
@AndrewKushnir

Description

@AndrewKushnir

Which @angular/* package(s) are relevant/related to the feature request?

compiler

Description

Currently, when a directive or a component use @Attribute to retrieve an attribute value from a host element, for example:

@Directive({
  selector: '[dir]',
})
export class Dir {
  constructor(@Attribute('priority') priority: string) {
    console.log(priority);
  }
}

The app will run with no errors when a value is defined statically in a component's template:

<img src="./test.png" dir priority="true" />

However when a binding is used:

<img src="./test.png" dir [priority]="true" />

the framework throws an error:

Can't bind to 'priority' since it isn't a known property of 'img'.

which is also correct, but we could improve the error message to include more info, for example:

Can't bind to 'priority' since it isn't a known property of 'img'.
Did you mean to bind to the priority @Attribute? Try XYZ.

(proposed by Kara in #45757 (comment))

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: compilerIssues related to `ngc`, Angular's template compilercompiler: template type-checkingfeatureIssue that requests a new featurefeature: insufficient votesLabel to add when the not a sufficient number of votes or comments from unique authors

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions