If you want to use shared state or functionality, you should use a service
instead of a controller. You'll probably want to use the module.factory()
method.

I'm not sure what functionality you're talking about using in other parts
of the application. If you're talking about i.e. pulling out the thing to
determine if something is an image, I don't see how it would be valuable
outside the context of a file input element.

It doesn't really make sense to share state for your directives through a
service (unless it's truly global state), you should instead use directive
controllers (which are isolated to the element that owns the directive or
its parents - meaning that you can have more than one directive of the same
type on the same page that are isolated).

This is an advanced topic, but what you probably want to do is use
ngModelController to handle this. The directive should not perform AJAX
requests, that should be in your application logic.

If you're not interested in digging into angular internals and learning how
the input/ngModel directives work, it looks like there's a basic directive
that will get you part of the way there here:

http://stackoverflow.com/questions/17063000/ng-model-for-input-type-file



On Thu, Feb 6, 2014 at 2:29 PM, Marc B <[email protected]> wrote:

> I suspect that you're misunderstanding what you should be doing, though
>
> Quite possible. So what I'm trying to do is create a file upload
> directive. Placed on a file input button it should onclick
> check if the file to be uploaded is image;
> fire an Ajax POST containg metadata and binary data of the image;
> show a thumbnail of an already uploaded image.
>
> I figured it makes no sense to stuff all this functionality in one
> directive - there might be other places in the app that need (part of) this
> functioniality and besides I think it makes sense to have an utils service
> containing this functionality.
>
> So what would be the best way to handle this?
>
> Marc
>
> --
> 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/groups/opt_out.
>



-- 
chrisrhoden

-- 
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/groups/opt_out.

Reply via email to