{"id":1503,"date":"2012-09-19T10:39:28","date_gmt":"2012-09-19T14:39:28","guid":{"rendered":"http:\/\/cd34.com\/blog\/?p=1503"},"modified":"2012-09-19T10:39:28","modified_gmt":"2012-09-19T14:39:28","slug":"angularjs-a-first-step","status":"publish","type":"post","link":"https:\/\/cd34.com\/blog\/framework\/angularjs-a-first-step\/","title":{"rendered":"AngularJS &#8211; a first step"},"content":{"rendered":"<p>If you&#8217;ve not heard of <a href=\"http:\/\/angularjs.org\/\">AngularJS<\/a>, I&#8217;m not surprised. It moves MVC or MV* to the browser and provides a unique, lightweight, powerful way to write apps that execute on the client side. Forms, validation, controllers, routes are all handled fairly easily.<\/p>\n<p>The one thing I look for in every framework I use is a decent form library. No form library, and my interest wanes quickly. I don&#8217;t know how frameworks can claim to speed up development if you have to hand code forms, do your own validation and handle the form submission. It isn&#8217;t like you don&#8217;t expect people to input data.<\/p>\n<p>The first thing with AngularJS that I ran into is the markup. While most frameworks have a template language that is executed before presentation, AngularJS&#8217;s markup is written directly in the HTML. The one thing that seems missing is the ability to do conditionals in templates. That was a design choice and a decent one to stand firm on, but, working around that to make a dynamic menu was a little complicated.<\/p>\n<p>Passing things to your $scope allow you to communicate from your controller to the page. When using a controller, your urls look like http:\/\/site.com\/#\/page, but, if you view source, the page looks rather barren. I know Google&#8217;s searchbots can crawl the site as it did about eight minutes after I created the site.<\/p>\n<p>There are a number of demos and videos and watching them gives you a fairly complete overview of AngularJS.<\/p>\n<p>Development was quick. I spent a total of three days writing a quick app to familiarize myself with it and overall, the documentation is excellent, the examples are pretty good and cover a wide variety of use cases. There is a learning curve, but, the documentation is written very well, explaining the why in addition to having functional documentation.<\/p>\n<p>To handle synchronous events with JavaScript&#8217;s async behavior, $q, a promise handler which works with a service was written. In your controller, you ask for a promise, hand it off to your service which resolves the promise, and your controller continues at that point, modifying the DOM on your page allowing for a very dynamic site.<\/p>\n<p>Form handling is superb. Validation of fields can be handled quickly and you can even specify regexes in the HTML for extremely tight validation. Once you&#8217;ve received the data, your controller can act on that data.<\/p>\n<p>Controllers and routes initially caught me off guard. When I first looked at them, I missed the ng-app specification and had to remove my controller declaration on my div from a prior iteration. Once I did that, and understood how partials worked, my app became a multipage app.<\/p>\n<p>I didn&#8217;t do much DOM manipulation, but, AngularJS has quite a few powerful methods that make it quite easy. Selecting and modifying DOM elements is quick, and, with a service\/controller setup, you can simply send changes through to the scope and they&#8217;ll be reflected.<\/p>\n<p>Overall, my first experience with AngularJS is a positive one.<\/p>\n<p>The first app I wrote was <a href=\"http:\/\/stravaperf.cd34.com\/\">StravaPerf<\/a> which utilizes the <a href=\"http:\/\/strava.com\/\">Strava<\/a> API and <a href=\"http:\/\/d3js.org\/\">d3.js<\/a> to display graphs showing rider improvement. While Strava&#8217;s API is quite robust, I&#8217;ve run into API limits in the past, so, I use <a href=\"https:\/\/www.varnish-cache.org\/\">Varnish<\/a> to work around the fact that JSONP isn&#8217;t supported, and, to cache the JSON responses coming back from Strava. This eliminates the need to have any backend or persistent storage. As a result, the app runs almost entirely from Varnish and only hits the backend on a cold start.<\/p>\n<p>AngularJS is quite powerful and easy to use. I can see a number of potential projects that could easily be handled with it that would be extremely dynamic and interactive. This would push the edge of the web and allow app-like behavior in the browser.<\/p>\n<div style=\"float:left;\">\n<div id=\"fb-root\"><\/div>\n<fb:like href=\"https:\/\/cd34.com\/blog\/framework\/angularjs-a-first-step\/\" width=\"250\" send=\"false\" show_faces=\"false\" layout=\"button_count\" action=\"recommend\"><\/fb:like>\n<\/div><div style=\"clear:both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>If you&#8217;ve not heard of AngularJS, I&#8217;m not surprised. It moves MVC or MV* to the browser and provides a unique, lightweight, powerful way to write apps that execute on the client side. Forms, validation, controllers, routes are all handled fairly easily. The one thing I look for in every framework I use is a [&hellip;]<\/p>\n<div style=\"float:left;\">\n<div id=\"fb-root\"><\/div>\n<fb:like href=\"https:\/\/cd34.com\/blog\/framework\/angularjs-a-first-step\/\" width=\"250\" send=\"false\" show_faces=\"false\" layout=\"button_count\" action=\"recommend\"><\/fb:like>\n<\/div><div style=\"clear:both;\"><\/div>","protected":false},"author":15,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[281,282,138,283,21],"class_list":["post-1503","post","type-post","status-publish","format-standard","hentry","category-framework","tag-angular","tag-d3","tag-javascript","tag-strava","tag-varnish"],"_links":{"self":[{"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/posts\/1503","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/comments?post=1503"}],"version-history":[{"count":4,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/posts\/1503\/revisions"}],"predecessor-version":[{"id":1509,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/posts\/1503\/revisions\/1509"}],"wp:attachment":[{"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/media?parent=1503"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/categories?post=1503"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cd34.com\/blog\/wp-json\/wp\/v2\/tags?post=1503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}