1

I have tried to search the world wide web for answers, but can't find any.

I have property in Aurelia like this:

@observable
public _name: boolean = false;

Then uses Aurelias *Changed like this:

 public async _nameChanged(): Promise<void> {
        //Do stuff
    }

Then in the html uses it something like this:

<div value.bind="_name"></div>

Now the question is, how in the world do I do to avoid getting the change method to get called when it is attaching to the viewmodel?

Or to but it simple, is there anyway to configure the Change listener to only listen to changes from the view. Because I am trying out a kind of "autoSaveFeture". And I only want the Change to happen if the user triggers the change from the view.

I do have a solution but that means I have to go away from the aurelia frameworks observable. But before I do that I would like to know if there is any solutions out there that I can't find or is not documented.

Like you could set settings on the @observable flag to only litsen to changes that has triggerd by the view..

If there is any question or Im describing the problem bad please let me know.

J4v4Scr1pt
  • 289
  • 5
  • 16
  • 2
    You could try something like this https://stackoverflow.com/a/53800299/801241 where you only add the observable to the properties on `attached()` event. – Qpirate Feb 21 '20 at 14:11
  • Interesting, I will check that one out – J4v4Scr1pt Feb 21 '20 at 14:38
  • That sugestion worked, but is there no other way. Like you could set the @observable flag to only litsen to changes that has triggerd by the view? – J4v4Scr1pt Feb 24 '20 at 09:29
  • you could just bind to the change event of the ui element. and not use observables. – Qpirate Feb 24 '20 at 10:36
  • How do you mean, mabey im slow but is that not what im doing with ".bind"? Like I wrote, I want to track changes made by the user not the app it self. Because then I can trigger a "autosSaveFeature" in the nameChange method. This means that I dont want a save button on my view. – J4v4Scr1pt Feb 24 '20 at 12:22
  • Sorry, please ignore that, i thought there might be a way to get around the value updating on a change event, but nope there is not. – Qpirate Feb 24 '20 at 14:56
  • no need to be sorry m8 :), ok then if no one else got a an ideá I going with your first suggestion, thx! – J4v4Scr1pt Feb 24 '20 at 19:33
  • I'm confused, are you using @bindable or @observable? There are subtle differences between the 2 – Arne Deruwe Feb 26 '20 at 07:44
  • Hi! ArneDeruwe Sorry I have made a misstake in the title.. :( It should say @observable – J4v4Scr1pt Mar 02 '20 at 07:23

0 Answers0