question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Template parser throws error when using custom properties for component

See original GitHub issue

As far I know, component selector can be any proper css selector. But, usually it is just an element tag name. I’ve created some tests of how Angular is pushing values of custom properties to elements. And when I try to set something like this:

<h1 [customName]="'custom name'"></h1>

Parser throws an error: Can’t bind to ‘customName’ since it isn’t a known native property Ok. I understand that we can not set custom properties which are not in prototype chain of native element.

If I change element to some custom tag name, it works:

<hello-world [customName]="'custom name'"></hello-word>

I think this is done like that because of web components lifecycle, but also for utilizing Components. However, as I mentioned above, Components can use other css selector than tag name. For example we can create component with that decorator:

@Component({
  selector: "#hello-world"
})

Then we can use any tag with proper id. This can be also native element. If we do so, parser throws an error:

Can't bind to 'customName' since it isn't a known native property ("
    <div id="hello-world" [ERROR ->][customName]="'custom name'"></div>

This is really confusing. If components should be created as custom tags, selector should be used as tag name, not css selector. If I can create component with css selector, then parser should not throws error for custom properties with native elements.

Link to “working” example.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
smallubancommented, Jan 7, 2016

Yes. There is no documentation yet for selector (https://angular.io/docs/ts/latest/api/core/ComponentMetadata-class.html), so I think this will be documented and the problem will be gone 😃

0reactions
angular-automatic-lock-bot[bot]commented, Sep 7, 2019

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

using custom structural directive throws an error in console?
I am using it like as follow from a component template . <ng-container *pcHasCampaignBudgetEnabled="currentUserAccount" pcColumnDef="budget" [ ...
Read more >
Unable to parse component template - Opster
A detailed guide on how to resolve errors related to "unable to parse component template"
Read more >
Custom elements - Knockout.js
Custom elements are a syntactical alternative to the component binding (and in fact, custom elements make use of a component binding behind the...
Read more >
Web container custom properties - IBM
The following is a list of custom properties that are provided with the Application Server. The topics, JavaServer Pages specific web ...
Read more >
nunjucks templating docs
If you are using a custom template loader that is asynchronous, see asyncEach ) ... It might be useful to not throw an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found