Questions tagged [angular2-databinding]
55 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
557
votes
31 answers
ExpressionChangedAfterItHasBeenCheckedError Explained
Please explain to me why I keep getting this error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked.
Obviously, I only get it in dev mode, it doesn't happen on my production build, but it's very annoying and…

Kevin LeStarge
- 8,142
- 4
- 21
- 34
9
votes
2 answers
Angular - Is binding a component method to DOM target property a wrong practice?
Say, I have a component which is used as following:
After reading data-binding related parts from https://angular.io/guide/template-syntax, it seem like the…

Uthman
- 9,251
- 18
- 74
- 104
5
votes
2 answers
Performance - Should two way data binding be avoided?
Sorry if the question is too basic.
I want to know if I should avoid two way data binding in my system. I can capture the values of the form in the submit the form without having to use two way data binding.
My question is whether the two way data…

Jobsdev
- 1,047
- 3
- 11
- 28
5
votes
1 answer
Function is getting called many times by using template interpolation?
Sorry for basic question, I am trying to understand the angular2 flow using basic example.
import { Component } from '@angular/core';
@Component({
selector:'my-app',
template:'Test {{ getVal() }}'
})
export class AppComponent{
…

wmnitin
- 3,387
- 1
- 13
- 19
3
votes
1 answer
Inserting HTML (with angular 2 directives) from the server into the DOM
I have ~2,000 lines of HTML code that I can retrieve from my Java server. This HTML code also has angular directives inside of it, such as ngIf* and (click) and [ngClass]. When I try to display that HTML in my client with such methods as the…

Mike K.
- 543
- 3
- 14
- 46
3
votes
1 answer
Data Binding causes ExpressionChangedAfterItHasBeenCheckedError
I'm new to Angular 4. I have a data binding field like below. But somehow, there is an ExpressionChangedAfterItHasBeenCheckedError.
3
votes
4 answers
Angular 2 RC5 [(ngModel)] Databinding Failure
I've been looking at this code for a bit now and I'm stuck: I have a form that I'm binding to a component model and the [(ngModel)] binding breaks the page - the page won't render. I get no compilation error and no runtime debugger error, but the…

Rick Strahl
- 17,302
- 14
- 89
- 134
2
votes
2 answers
How do I get a string value from service in an Angular component?
I am trying to get the value of a string variable explanationText from my QuizService to display in my di-quiz component template using data-binding. console.log is showing undefined for explanationText and data-binding to the template isn't…

integral100x
- 332
- 6
- 20
- 47
2
votes
1 answer
How can I bind 2 variables inside 1 property binding in angular 2?
I'm trying to dynamically generate and use form controls from my json data. A simple experiment I came up with to figure out the mechanics I need to apply goes as follows.
variables defined in class
demoA: string = 'name';
demoB:…

Optiq
- 2,835
- 4
- 33
- 68
2
votes
4 answers
Why passing custom object in @Input doesn't work?
I am trying to pass a custom object through @Input. But, I'm getting null as output.
This is my child component class:
import { Component, OnInit, Input } from '@angular/core';
import { Element } from…

BlackBeard
- 10,246
- 7
- 52
- 62
2
votes
1 answer
String interpolation in Angular2 event binding
I'm using an ngFor to list my data, and would like to be able to click an element and have it call a method in my component class, identifying which element of the data it is. My attempts basically came to something like this:

Incinirate
- 114
- 2
- 11
2
votes
1 answer
What's the advantage/disadvantage of writing `[defaultColor]="'violet'"` in Angular 2
In angular.io Docs Advanced you can read following code:
Highlight me too!
I thought that when binding to a constant value, it should be sufficient (and more efficient?) to…
hgoebl
- 12,637
- 9
- 49
- 72
2
votes
1 answer
Angular2 innerHtml binding breaks data binding
I am trying to bind to innerHtml while keeping data binding. This does not work (outputs {{myVar}}).
@Component({
selector: "test",
template: `
`,
})
export class TestComponent{
title = "My Title";
…

maxbellec
- 16,093
- 10
- 36
- 43
1
vote
0 answers
what is the meaning of "after Angular first displays the data-bound properties"
I'm following the Angular documentation about the ngOnInit lifecycle until it gets really confused by saying "after Angular first displays the data-bound properties". Btw, you can check the documentation here. I guess the meaning of the word display…

Hunq Vux
- 35
- 2
- 7