I'll try to clarify without writing the plunker, if it doesn't work out 
then I'll get down to it.

I have a navigation bar on the left which is showing workflow steps. 
Modules of the application can register their own steps using the 
WorkflowService.
The first screen of the application is editing a list of partners. This is 
done by displaying a list of text fields which can be edited, added to and 
deleted. I want to create a new workflow step for each partner. Adding and 
deleting is not a problem, as I can do that in the click event handlers, 
but when the user is editing one of the text fields it's hard for me to 
update the title of the workflow step. The workflow steps are different 
objects then the partners, so there can be no data binding between them.
The problem is I don't know how to watch for changes in the names of the 
partners (editing of the text fields). If I use watch ("partners", 
function(new, old){}, true) then I'll get the whole partner list and have 
to find the actual changed partner name myself by comparing the old and new 
object trees. This seems horribly inefficient to me. What I would like is 
to get the actual partner which has been modified. Of course I could put 
listeners on the text fields but that would beat the whole purpose of the 
data binding.

Data model:
project = {
  partners: [{ //we are editing the list of partners
    name: 'partner1',
    ...},
    ...
  ]
}

workflow = {
  steps: [{
    title: 'partner1',
    associatedPartner: <reference to partner1> //needed to find step 
belonging to given partner
    ...},
   ]
}

* when new partner added to model contoller calls WorkflowService to add 
new step
* when partner name changes controller calls WorkflowService to update the 
title of step belonging to that partner.

Does that make it clear, or should go ahead and create the plunker?

On Tuesday, January 20, 2015 at 1:13:21 PM UTC+1, Sander Elias wrote:
>
> Hi Ádám,
>
> If you need some data in multiple parts of your app, the usual way to do 
> is to put that data into a service, and share that service where you need 
> it. If you do this correctly, you don't need a watch at all, Angular will 
> make sure everything stay's in sync.
> When you have issues like this, it helps if you provide a plunker 
> <http://plnkr.co/edit/tpl:UgRR2r6xmQUykBeltXPY?p=preview>illustrating 
> your problem, that way, it becomes easier to help you.
>
> Regards
> Sander
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to