Okay, I know what all of those individual things are, but I don't really 
get how to wire them together in the way that you're talking about. Are you 
saying that I should build a directive to handle the child element?

Maybe I can detail what I did when I last built something like this in 
Angular, for discussion on how to do it better?

The site is built in ASP.NET MVC, and the parent item is a cshtml view that 
has an Angular controller like normal. The parent controller gets it's data 
using a $http call, and on success, sets a $scope variable to the data that 
the child needs. The parent cshtml has a @Html.Partial that renders the 
child view on the server side, and passes through a named property with the 
name of the parent scope variable to get the data from.

The child view specifies the controller, and has a ngInit directive that 
calls a scope function and passes it the string name of the parent scope 
variable to watch that it got through the Partial render call. The child 
scope function sets a watch on the parent scope for the given variable 
name, and when triggered, sets a child scope variable to the new value.

On Monday, August 24, 2015 at 6:02:43 PM UTC-5, Stewart Mckinney wrote:
>
> You are looking for Isolate Scopes. They allow pretty much everything you 
> are asking for. You should be using a service to "grab" the data, but a 
> controller should be using the service.
>
> In other words, a parent controller would load those 0,1,2 or 3 models and 
> then pass each to an isolate scope.
>
> As an added bonus,  if you really want it reusable, I would make your 
> scope definition and controller logic such that a promise or object could 
> be passed to the scope ( using $q.when works ).
>
>
> On Mon, Aug 24, 2015 at 6:32 PM, Mason Gup <[email protected] 
> <javascript:>> wrote:
>
>> I used to do mostly WPF/WinForms development, and we're using mostly 
>> Angular at my new company. I'm working on getting my head around the 
>> Angular way to do things, and there's one part that I can't seem to find an 
>> Angular equivalent or alternative for.
>>
>> In WPF, I can build a UI component for something that's used in multiple 
>> places at multiple levels, and create it in code, passing an object to 
>> display to it. In any interface I build that uses this, I can include zero, 
>> one, or multiple of these components, and since they get created and passed 
>> their data in the code for the parent object, it's clear what data they're 
>> displaying and where it's coming from, with the child items having no 
>> dependency on the parent item structure.
>>
>> I can't seem to find a clean way to do anything like this in Angular. I 
>> can create a child Controller and attach it to a child item inside a parent 
>> with the usual ngController directive, and even do several of them per 
>> page, but I can't seem to find a good way to pass data to it from the 
>> parent. Using ngInit seems to kind of make sense, as I can pass a 
>> particular item on the parent $scope to a particular variable on the child 
>> scope, but this is apparently not the Angular way, and I'm supposed to be 
>> using a Service instead.
>>
>> But since Services are singletons, I don't understand how I can have 0, 
>> 1, 2, or 3 child controllers and pass each of them data from a different 
>> variable in the parent controller without introducing dependencies on the 
>> parent in the child. I could create a service and have the parent item 
>> store the data in it, and have the child controller retrieve it, but if I 
>> had 3 copies of the same child controller, all displaying data from a 
>> different object that the parent has, how would each one know what to get 
>> from the service?
>>
>> -- 
>> 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] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> Visit this group at http://groups.google.com/group/angular.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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