I have this generic method on my api objects which adds a related object to
a relation type.
So, adding a tag to a document is like document.$addRel('tags', tag) and
adding a follower to a document is document.$addRel('followers', profile).
It's handy, and a nice uniform interface. There's a lot of other
relationships (profile reacted to object, profile is a member of a
community, etc).
In my UI, there's a bunch of little widgets for adding things to other
things. One such is a generic selector, <trellis-person-selector
on-select='&'>. It knows enough to grab some profiles, run a search on the
backend if the user types enough, and so on. When the user selects a
person, it calls scope.onSelect with the selected person.
What I *thought* I had to do was define a bunch of helper methods, like
document.addEditor(profile) and so forth, which called
document.$addRel('editor', profile), because onSelect only really wants to
be called with a profile object -that's the point to encapsulation and
stuff. I was thinking about doing some fancy function currying, just to
save time and effort, but angular beat me to it.
turns out, in the enclosing context, if I do <trellis-person-selector
on-select="document.$addRel('editors', profile)"> (note that the first
argument is a string literal, while the second argument is a variable,
more-or-less), angular curries the function call for me. That's a side
effect of how it handles & scope objects, I imagine.
Inside the trellisPersonSelector link function, I call things like
onSelect({profile: theSelectedProfile}) and it all works just fine.
Ampersand scope is weird and hard to wrap my head around, but now that I've
gotten a handle on it, it's pretty neato.
e
--
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.