Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if.bind null check is requiring me to set object to null twice #79

Closed
cknightdevelopment opened this issue Feb 10, 2016 · 2 comments
Closed

Comments

@cknightdevelopment
Copy link

Here is the relevant code for the issue I am experiencing:

JS

export class App {
  person = {
    name: "Chris"
  }

  makeNull() {
    this.person = null;
  }
}

HTML

<template>
  <div if.bind="person">
    <input type="text" value.bind="person.name" />
    <p>
      The person's name is ${person.name}
    </p>
  </div>

  <div if.bind="!person">
    Person is null
  </div>

  <button type="button" click.delegate="makeNull()">Make Person Null</button>
</template>

Note: I have a plunker to help illustrate this issue (takes a few seconds to load in plunker)

As you can see I have two simple if.bind's checking if person is truthy. If it is, the person's name is displayed in a textbox and as part of an message, otherwise the text Person is null is displayed. When I click the button, I set the person object to null via the makeNull() method. However, the textbox and message are still displayed (even though the value of person.name is correctly updated in the UI?). When I click the button a second time, the if.bind's seem to pick up the change and the Person is null text is displayed. It is worth noting that if I remove the textbox (<input type="text" value.bind="person.name" />), everything works fine.

I would expect everything to work on the first button click (first time setting person to null). Am I doing something wrong or against convention? Is this a bug? Let me know if I can provide more information.

@gheoan
Copy link

gheoan commented Feb 10, 2016

The two-way binding somehow causes this issue. With value.one-way="person.name" instead of value.bind="person.name" it works fine.

@jdanyow
Copy link
Contributor

jdanyow commented Feb 10, 2016

@cknightdevelopment - you're not doing anything wrong- it's this issue:
aurelia/binding#205

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants