This is the way I see this:
Controllers should be kept as small as possible, and be focussed on your
application/business logic
When you want to code something the user is going to interact directly
with, use a directive. Think of directives as "components"
>From the very small amount of info you provided (not seeing the whole
picture doesn't really help), I'd create a directive (the component) that
can be configured from the application's controller. Say your component is
meant to be a drawboard/whiteboard thing, create a directive you would use
like so (this is merely a quick suggestion, there would probably be better
approaches to this kind of "problems"):
<div ng-controller="drawCtrl">
<drawboard stroke="{width: 1, color: 0x000000, [...]}"
background-color: "0xffffff"
[... any other property you want to feed to your
component ...]>
</drawboard>
</div>
The "DrawCtrl" is specific to *this* specific application needs/logic; It
could be defined in different ways but I just put it in an ng-controller
for simplicity's sake.
You could create variables on that controller's $scope with the options you
want to pass to the directive (and use <drawboard stroke="strokeOptions"
... />, "strokeOptions" being defined in $scope.strokeOptions)
Then your drawboard's only role is to render the clicks of the user with
the options it was passed. From the directive's controller or link
function, you could $watch on the directive's $scope for changes in these
property, meaning if you change the property object in your CrawController,
the directive will pick up that change accordingly.
This way your drawboard directive is an independant component that you
could re-use in different app/contexts
Hope this helps
On Saturday, March 29, 2014 2:08:04 PM UTC-4, Kamal wrote:
>
> Mitchell,
>
> It depends, do you have methods to which you pass the values to calculate
> the width, clear etc.., in this case an controller is the easy way but it
> would create a new scope. If you want to share the scope between multiple
> directives or expose some details to other lib's such as JQuery using
> attributes or Using similar type of complements at multiple places better
> go for an directive, you can expose some functions/variables into the scope
> of the directive if need like for clear.
>
> Regards,
> Kamal
>
> On Saturday, 29 March 2014 23:21:16 UTC+5:30, Mitchell Hudson wrote:
>>
>> I'm new to AngularJS. I'm working with canvas, I have a directive that
>> sets up some JS for drawing. I wan to add a couple actions to set the line
>> width and clear the canvas. Should I tie these features to a Directive, or
>> should I use a Controller?
>>
>> Thank in advance.
>>
>
--
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.