Angular (Javascript) -- Does this thing have legs?

Status
Not open for further replies.

Nimdok

Ars Scholae Palatinae
1,214
I have a largish web project that uses a bunch of Javascript and has jQuery as the only library dependency. I heard some of the buzz on Angular and decided to evaluate it on a much smaller project we have in-house.

The short of it is that I'm not much enjoying this excursion into Angular. I like the idea of moving some of my heretical, DOM-modifying Javascript back into HTML. It'd make prototyping easier, and it'd be great to use a framework that is commonly known. I watched the Angular tutorial videos, and I get how to do simple things with it. The basic cases do work fine! But when I start throwing in the background events coming in over websockets, drag and drop, canvas renders, etc...I actually just can't figure out how I should do it. That is, I can't even do it badly in Angular. I don't know what combination of directives/controllers/templates gets me to where I was with basic jQuery.

So what's the deal here? Am I just a bad dog that can't be housebroken or are other people getting similar vibes from this framework? If you use Angular for some fairly complex stuff, what resources do you recommend?

And what the heck is the word on 2.0?
 

Paul Hill

Ars Legatus Legionis
19,890
I heard loads of nice things about Angular but it was way too big a gulp for the project I was working on when I just wanted what I think you just want - some decent presentation/logic separation right?

I ended up using Knockout for the front end and TypeScript classes for the ViewModel layer and it's just fabulous. Really simple really extensible data binding stuffed inside a single "data-bind" attribute or inside comments.

http://knockoutjs.com/

I'm slightly baffled why KO doesn't get more love here, I think little bits of tooling that work together just wipe the floor with big-bang monoliths like Angular, even for greenfield sites. Hope this helps!
 

krimhorn

Ars Legatus Legionis
39,865
[url=http:/civis/viewtopic.php?p=28635947#p28635947:1ofnk9u8 said:
Nimdok[/url]":1ofnk9u8]I have a largish web project that uses a bunch of Javascript and has jQuery as the only library dependency. I heard some of the buzz on Angular and decided to evaluate it on a much smaller project we have in-house.
As an evaluation a small project is probably the right approach but, generally, I wouldn't recommend Angular on a small project. At least not a "simple" small project. It's much too heavy-weight for that.

The short of it is that I'm not much enjoying this excursion into Angular. I like the idea of moving some of my heretical, DOM-modifying Javascript back into HTML. It'd make prototyping easier, and it'd be great to use a framework that is commonly known. I watched the Angular tutorial videos, and I get how to do simple things with it. The basic cases do work fine! But when I start throwing in the background events coming in over websockets, drag and drop, canvas renders, etc...I actually just can't figure out how I should do it. That is, I can't even do it badly in Angular. I don't know what combination of directives/controllers/templates gets me to where I was with basic jQuery.
I've found the bolded to be the biggest hurdle (even today with the documentation in a much better shape than it was a year ago) in figuring out Angular. I actually can't provide much direct help with the scenarios you've described as I haven't used them in an Angular app yet but some quick Googling gave up a couple of modules that might get you on the right track: ng-websocket (module that has a provider and service for handling websocket connections), Working with Canvas and AngularJS and Canvas drawing directive? (short version is that Angular is not really a canvas oriented framework, it's much more of a two-way data binding framework with view altering capabilities based on that data (MVVM style) so your best bet sounds like to manage whatever data that feeds the canvas with Angular and then step outside of Angular to handle the actual canvas work.). "Drag and Drop" has several third party directives already created D&D for AngularJS, angular-dragdrop, ngDraggable,ngRepeat Drag n Drop and probably many others.

So what's the deal here? Am I just a bad dog that can't be housebroken or are other people getting similar vibes from this framework? If you use Angular for some fairly complex stuff, what resources do you recommend?
So far I haven't come across a single thing that I needed to accomplish that I couldn't find a resource explaining how someone else had already accomplished that goal. Generally that starts at a StackOverflow question and breaks from there to various one-off blogs with code examples. You do start to get a hang of what components get used to accomplish certain kinds of tasks (broadly speaking view controls, validators or anything reusable that's view related are Directives, Controllers handle the ViewModel for each view template and anything that needs to persist in the app or facilitate inter-Controller communication (or outside world communication for that matter) are Services. There are other components like $filter and interceptors on the $httpProvider that serve general roles as well but aren't necessarily as needed as those first three.

And what the heck is the word on 2.0?
At this point nothing other than it's being worked on and the broad strokes plan. Honestly, Angular 1.x isn't going anywhere any time soon even if 2.0 were to roll out today. If it does then it will be because 2.0 killed trust in the Angular steering team not to leave developers hanging with an unsupported framework not because people moved on to 2.0.
 

krimhorn

Ars Legatus Legionis
39,865
[url=http:/civis/viewtopic.php?p=28636275#p28636275:3ecfi5i2 said:
Paul Hill[/url]":3ecfi5i2]
I'm slightly baffled why KO doesn't get more love here, I think little bits of tooling that work together just wipe the floor with big-bang monoliths like Angular, even for greenfield sites. Hope this helps!
Honestly? It's a kludgy early JS two-way databinding framework that's a pain to work with. The requirement of performing so much of the two-way unpacking yourself rather than allowing the framework to abstract that away is a key frustration of mine. With Angular I can interact with any object on any scope (that I have access to) just like I was interacting with any other JS object. The details that wrap that object and allow the two-way databinding to occur don't get in the way at all whereas they're everywhere in KO.
 

drogin

Ars Tribunus Angusticlavius
8,283
Subscriptor++
I've been using ReactJS using the Flux architecture pattern, and it's been working really well.

AngularJS seems to work fine, but you have to buy into it completely. You can't really mix and match a lot of stuff. There's a lot of really dense functionality that takes a while to learn as well.

ReactJS is infinitely simpler because it only tries to solve one problem: minimize the number of DOM manipulations that you do.

Flux takes it a step further by introducing a uni-directional dataflow to drive state changes and thus rendering. I like the analogy they make to working with a desktop graphics package. You set up your "scene" using state information, then render the entire scene based on a snapshot of that state. The thing ReactJS adds to that mix is it's ability to do a diff of two "scene graphs" and optimize the number of actual DOM manipulations that take place.

It is kind of a choice as to where you want to fall on the spectrum. Angular is an opinionated framework, and there's something to be said for that. ReactJS/Flux is not as opinionated, and there's something to be said for that as well.
 

Marco

Ars Scholae Palatinae
1,346
I can certainly relate.

I recently used Angular to redo a project I worked on (which had become a big hairy chunk of jQuery spaghetti code) and I too found myself totally lost in the beginning. Angular actually isn't that complicated, but it just requires a totally different way of thinking. If you're coming from years of simply manipulating DOM elements with jQuery then Angular will take quite a bit of getting used to. Tutorials are nice, but somehow real world applications are never quite like the tutorials :p I too found myself often wondering how to perform relatively simple tasks that would have taken 5 minutes with jQuery or even plain JavaScript. One of the biggest struggles I had was taking pieces of actual functionality that I had already written, and then finding a way to do the same thing with Angular. The solution was usually pretty simple but sometimes took a while to find, simply because I was used to a different way of thinking. Also, Angular is pretty flexible and forgiving and there usually isn't one best way to do anything (in spite of what a lot of Stack Overflow users will have you believe). Like how you have factories, providers and services, and they are all aliases for pretty much the same thing. It's confusing and doesn't do anybody any favors.

Trying to integrate third party libraries (which more often than not require jQuery) may also give you headaches. For example, I spent ages trying to find the best way to integrate Magnific Popup into my project and eventually just built a small service around it (with 'open' and 'close' methods that are pretty much just references to $.magnificPopup.open/close; yeah, I included jQuery in my project... bite me :p) and called it a day. I also struggled for a bit with canvas elements, as well, but creating a directive and then doing all the canvas drawing in the link function is pretty much the only way. Often, it's helpful to just google "angular" plus whatever you're trying to accomplish. Usually, someone will have written a directive you can use for inspiration.

Also a big hurdle to me was all the stuff that seems to surround Angular. You're looking to get started with Angular and suddenly you come across all these people talking about Bower, Yeoman, Git, Grunt, Node.js, and what have you. I know that actually stopped me from getting into it before, because it all just seemed so intimidating. I think one of the biggest eye openers for me was the realization that you don't have to be a sheep and do everything exactly the cool blogging hipsters tell you to do them simply because it works for them. Once I discovered I could just start out loading Angular from a CDN into a bare bones web page (like I would do with jQuery) and then move on from there, it made me a little more confident that I wasn't a complete idiot for not having a clue what these people were talking about ;) Get comfortable with the framework first, then worry about the other stuff. It's too easy to get sucked into that and end up overwhelmed by it. Hell, I've been working with Angular for a couple of weeks and I'm still not writing unit tests... it's just too damn complicated and a lot of arbitrary syntax to learn to get into it quickly.

So yeah, the learning curve is steep, but it does get better and you'll start to see the benefits sooner or later. Once you adjust to life with services, controllers, scopes, directives and dependency injection, you'll figure out ways to do what you want in a sensible way. At first it may seem like you will never get there, but you will. And even if you won't, there's plenty more fish in the sea. Don't feel bad if you decide that it just isn't for you, for whatever reason.

Re: KnockoutJS: I've used it in smaller projects and I thought it was fine for what it is, which is a data binding library. It doesn't have built-in routing capabilities and its abilities to work with templates are fairly limited, so once you get into SPA territory, Knockout doesn't seem like the most obvious choice. If you just want data binding, though, it's fine. It's been around for a while and has a proven track record.
 

Zaskar

Ars Praefectus
3,347
Subscriptor
Jquery is what does not have legs, the ecosystem is far too fat and limited in how it interacts with the browser.

Controllers:
Do as little as possible here, models do everything data. Views do everything human. Controllers are a lynchpin between.

Views:
The big thing is to forget the jquery way of working within html, angular expects you to expand the markup vocabulary.
 

krimhorn

Ars Legatus Legionis
39,865
[url=http:/civis/viewtopic.php?p=28640695#p28640695:3a4fysah said:
Marco[/url]":3a4fysah]yeah, I included jQuery in my project... bite me :p ...
So long as you invoke the JQuery from within a $scope controlled function and don't manipulate the data you'll generally be fine. Thanks to AngularUI-Bootstrap not getting the Popup quite right (you can't explicitly invoke or destroy them with AngularUI's implementation) I had to fall back on the OG Bootstrap 3 implementation. It works well and since it's nothing more than display oriented I don't have to worry about Angular not "knowing" about any changes that might be made to the data (since there will be none).

I do usually try to find a directive that serves my needs as well as a JQuery plugin that exists would. Or write my own if I can't find one. At this point not finding something that suits my needs well doesn't happen all that often.
 
Status
Not open for further replies.