Just using angularJS's data-binding?

3,320 views
Skip to first unread message

ItsLeeOwen

unread,
Apr 5, 2012, 11:35:48 PM4/5/12
to ang...@googlegroups.com
I've heard repeatedly that angularJS is good at being minimally sprinkled in projects.  I'd love to use it's data-binding features between a controller class, and target element.  However I'd also like to be able to do DOM manipulation, and listen to events from within the controller class.  I know this is a dastardly deed, but from what I can tell, angularJS does not expose the target element anymore.  Has anyone any experience using angularJS specifically for linking a controller to target element, with data-binding, without the strict MVC separation?

ItsLeeOwen

unread,
Apr 5, 2012, 11:54:23 PM4/5/12
to ang...@googlegroups.com
I suppose I could just grab the target element with a jQuery selector.

Misko Hevery

unread,
Apr 6, 2012, 12:49:26 AM4/6/12
to ang...@googlegroups.com
In the controller just inject $element or in ng-click just get the element from $event.

Yes this goes deep against the angular way....

On Thu, Apr 5, 2012 at 8:54 PM, ItsLeeOwen <devel...@coderebelbase.com> wrote:
I suppose I could just grab the target element with a jQuery selector.

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/wyYSJm8mkdUJ.

To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.

ItsLeeOwen

unread,
Apr 7, 2012, 3:30:37 PM4/7/12
to ang...@googlegroups.com
How would you inject $element in the controller?  Is there documentation on this?  Thanks.


Vojta Jína

unread,
Apr 7, 2012, 3:40:01 PM4/7/12
to ang...@googlegroups.com
Why do you want that ? That's gonna be hard to test.

Can you send an example (eg jsfiddle), what you are trying to achieve ?
I believe, there is a better way...

If you really want to shoot yourself, feel free to do it, here is the gun :-D
function Controller($element) {}


V.


On Sat, Apr 7, 2012 at 12:30 PM, ItsLeeOwen <l...@coderebelbase.com> wrote:
How would you inject $element in the controller?  Is there documentation on this?  Thanks.

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/gV-YbxmqsgMJ.

ItsLeeOwen

unread,
Apr 7, 2012, 4:02:29 PM4/7/12
to ang...@googlegroups.com
To check the element for custom directives, and in some cases be evil and shoot myself in the foot with event listeners/handlers in the controller.  Although I see the value of it, I'm not concerned with strict adherence to a unit-testable MVC app.

http://jsfiddle.net/ItsLeeOwen/S3BxD/

If I set $element as the first param in my Controller, it is undefined.  I've been passing $scope as the first param.



Daniel Nelson

unread,
Apr 7, 2012, 4:17:39 PM4/7/12
to ang...@googlegroups.com
Hi Lee,

I'm not sure what you are trying to achieve, but I cleaned up your
fiddle a little: http://jsfiddle.net/bluejade/S3BxD/3/

Hopefully that will give you a better starting point to try things out.

Cheers,

Daniel

Vojta Jína

unread,
Apr 7, 2012, 4:18:46 PM4/7/12
to ang...@googlegroups.com
It works fine:

You should do that inside directive, it would be way simplier.

V.

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/o8WTtpb3uuoJ.

ItsLeeOwen

unread,
Apr 7, 2012, 4:48:28 PM4/7/12
to ang...@googlegroups.com
Haha, thanks for the example, it is working indeed!



Reply all
Reply to author
Forward
0 new messages