0

I have objects coming in to my array. When change the value of the objects, let's say id. I need an event or something like that to be triggered.

This is how I add my objects:

 const entry= new CompletableEntry('models.Address.addressLine2._TITLE');
 this.globalLoadingScreenService.addTask(entry);
 task.updateID(3);

Updating the ID won't trigger anything but I have a function that needs to be triggered when a value changes. The function checks if all the objects have status of complete and if yes it will delete all items in array.

I know one way to get this would be by adding them trough my service but I kind of require solution that won't update the task status trough service.

1 Answer 1

2

You can either create a custom observable array to which you can subscribe to. This might help.

What I came up with is you can create a BehaviourSubject and subscribe to it.

import { BehaviorSubject } from 'rxjs';
arrayChanged = new BehaviourSubject(false);

//The function where actually the array is updating
fun update() {
    ...
    this.arrayChanged.next(!this.arrayChanged.value);
}

// Then to listen to the array changes.

this.arrayChanged.subscribe( value => {
    //The function you want to run goes here.
    // this block runs everytime there is some change in the behaviour subject
})

Sign up to request clarification or add additional context in comments.

1 Comment

I used your answer but in a different way. When a status is changed a created a field completed which is a BehaviourSubject, so when I add a new entry a subscribe to it and when it changes I get a trigger. Also it would work if I used the status as a BehaviourSubject. I'll modify your answer and give and select it as the right answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.