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.

Input property doesn't change value

See original GitHub issue

🐞 bug report

Description

I created a component with some input properties. I use two-way binding for one property and change value inside the component and then change it in a parent component. After some actions, value stops changing.

πŸ”¬ Minimal Reproduction

An example

  1. Change the value of the input.
  2. You can see β€œValidation message”
  3. Then type again -> β€œValidation message” is gone
  4. After the next typings message doesn’t appear

But I want to see the message after changes.

πŸ”₯ Exception or Error





🌍 Your Environment

Angular Version:





Anything else relevant?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
EmaGhtcommented, Nov 28, 2019

when the β€œchange” event of this input

<input (change)="handler($event)" />

gets triggered, you first do this:

this.isValid = true;

and then you emit your output with

this.valueChanged.emit(e.target.value);

on which app.component is listening on, which does this:

this.isValid = false;

Notice that the β€œisValid” variable of app.component is in turn bound to the ngModel of β€œmy.component”

Basically, before Angular’s change detection can run you are changing the input value twice, bringing it always back to it’s invalid value, therefore Angular cannot pickup any change.

As a test, change this in app.component: valChanged(val: string) { if (val !== "test") { this.isValid = false; } }

to this: valChanged(val: string) { if (val !== "test") { setTimeout(()=> {this.isValid = false}); } }

Welcome to Change Detection

0reactions
angular-automatic-lock-bot[bot]commented, Jan 3, 2020

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

Angular Input value doesn't change - Stack Overflow
Now when I click on an object in the parent component, the details will be loaded in de detail component, but when I...
Read more >
How to detect @input value changes in Angular Child ...
In this tutorial we learn how to detect @input value changes in Angular Child component with simple examples. Table of Contents Using @input...
Read more >
Why Angular Input Setter is Only Being Fired Once
Thus if we pass into the input property with an observable object which contains the same value, Angular will take it as a...
Read more >
How to detect when an input() value changes in Angular
Detect when input value changes in Angular Β· 1. Using the ngOnChanges() lifecycle method Β· 2. Using Input Setter and Getter Property Β·...
Read more >
How to detect when an @Input() value changes in Angular?
@Input() is basically a decorator to bind a property as an input. It is used to pass data i.e property binding from one...
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