Questions tagged [angular2-template]

For questions referencing Angular Template Syntax including: interpolation, input(property) bindings, output(event) bindings, two-way binding, local variables, star syntax, etc. This tag is specific to angular version 2.x and above

Tag content based loosely off Victor Savkin's Angular Template Syntax article

2881 questions
1083
votes
24 answers

Angular HTML binding

I am writing an Angular application and I have an HTML response I want to display. How do I do that? If I simply use the binding syntax {{myVal}} it encodes all HTML characters (of course). I need somehow to bind the innerHTML of a div to the…
Aviad P.
  • 32,036
  • 14
  • 103
  • 124
474
votes
28 answers

Angular 2 Scroll to top on Route Change

In my Angular 2 app when I scroll down a page and click the link at the bottom of the page, it does change the route and takes me to the next page but it doesn't scroll to the top of the page. As a result, if the first page is lengthy and 2nd page…
342
votes
3 answers

No provider for TemplateRef! (NgIf ->TemplateRef)

I'm trying to show a checkmark if an answer is the accepted answer: template: `
` But I get this error: EXCEPTION: No provider for TemplateRef! (NgIf ->TemplateRef) What am I doing wrong?
Mark Rajcok
  • 362,217
  • 114
  • 495
  • 492
305
votes
2 answers

How can I write data attributes using Angular?

I feel like I am missing something. When I try to use a data attribute in my template, like this:
  1. {{ section.text }} …
Serj Sagan
  • 28,927
  • 17
  • 154
  • 183
279
votes
11 answers

How to add "class" to host element?

I dont't know how to add to my component a dynamic class attribute but inside the template html (component.html). The only solution I found is to modify the item via "ElementRef" native element. That solution seems a little…
lascarayf
  • 3,423
  • 3
  • 19
  • 24
249
votes
41 answers

Can't bind to 'ngForOf' since it isn't a known property of 'tr' (final release)

I'm using Angular2 2.1.0. When I want to display a list of companies, I got this error. in file.component.ts : public companies: any[] = [ { "id": 0, "name": "Available" }, { "id": 1, "name": "Ready" }, { "id": 2, "name": "Started"…
Mourad Idrissi
  • 3,455
  • 5
  • 17
  • 29
226
votes
2 answers

What is let-* in Angular 2 templates?

I came across a strange assignment syntax inside an Angular 2 template. It appears that let-col and…
Steven Liekens
  • 13,266
  • 8
  • 59
  • 85
210
votes
13 answers

How to truncate text in Angular2?

Is there a way that I could limit the length of the string to a number characters? for e.g: I have to limit a title length to 20 {{ data.title }}. Is there any pipe or filter to limit the length?
him
  • 3,325
  • 3
  • 14
  • 17
191
votes
6 answers