<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:series="http://organizeseries.com/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>rabidGadfly</title>
	
	<link>http://rabidgadfly.com</link>
	<description>Coding Ideas, Experiments and Solutions</description>
	<lastBuildDate>Tue, 23 Apr 2013 18:21:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/rabidGadfly/blog" /><feedburner:info uri="rabidgadfly/blog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>How to Load External Data Into a Fiddle</title>
		<link>http://feedproxy.google.com/~r/rabidGadfly/blog/~3/IdwFZD9mg_M/</link>
		<comments>http://rabidgadfly.com/2013/03/how-to-load-external-data-into-a-fiddle/#comments</comments>
		<pubDate>Wed, 20 Mar 2013 14:47:55 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cross-domain]]></category>
		<category><![CDATA[fiddle]]></category>
		<category><![CDATA[headers]]></category>
		<category><![CDATA[jsfiddle]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[origin]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[XMLHttpRequest]]></category>

		<guid isPermaLink="false">http://rabidgadfly.com/?p=816</guid>
		<description><![CDATA[If you attempt to load data from an external domain into a Fiddle you’re likely going to receive an XMLHttpRequest error that looks something like “Origin is not allowed by Access-Control-Allow-Origin”. You can use JSFiddle’s echo requests if you just want to simulate returning data, but sometimes you want to demonstrate an actual retrieval. Here's how it's done: <a href="http://rabidgadfly.com/2013/03/how-to-load-external-data-into-a-fiddle/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>If you attempt to load data from an external domain into a Fiddle you’re likely going to receive an XMLHttpRequest error that looks something like “Origin is not allowed by Access-Control-Allow-Origin”. You can use JSFiddle’s echo requests if you just want to simulate returning data, but sometimes you want to demonstrate an actual retrieval. </p>
<p>Legitimate security concerns regarding cross-site HTTP requests are the reason why you can’t simply read in any old file. However, using appropriate page headers makes accessing files from other domains possible. So, if we can set page headers in a file that returns our data, it should be accessible, right? Right! </p>
<p>This can’t be done using a JSON file, but it <em>can</em> be done in a PHP file that is setup to output JSON. The PHP code would look something like this:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
// Allow access from anywhere. Can be domains or * (any)
header('Access-Control-Allow-Origin: http://fiddle.jshell.net');

// Allow these methods of data retrieval
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');

// Allow these header types
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');

// Create our data object in that crazy unique PHP way
$arr = array(array(&quot;id&quot; =&gt; 1, &quot;character&quot; =&gt; &quot;Minstrel&quot;, &quot;line&quot; =&gt; &quot;And Saint Attila raised the hand grenade up on high, saying, 'O Lord, bless this thy hand grenade, that with it thou mayst blow thine enemies to tiny bits, in thy mercy.' And the Lord did grin.&quot;));

// Return as JSON
echo json_encode($arr);
?&gt;
</pre>
<p>Note that you don’t have to use PHP. You can use just about any server side scripting language; ASP, .NET, ColdFusion, Ruby, etc., as long as you set the headers properly.</p>
<p>Check out an example:<br />
<p>[There is a JSFiddle embedded in this post. Please follow the link below or go to the site to see this JSFiddle.]</p><p><a class="ia-jsfiddle-link" href="http://jsfiddle.net/rabidGadfly/bNyqY">View this on JSFiddle</a></p></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=IdwFZD9mg_M:GzFj_m-p4Hk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=IdwFZD9mg_M:GzFj_m-p4Hk:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=IdwFZD9mg_M:GzFj_m-p4Hk:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=IdwFZD9mg_M:GzFj_m-p4Hk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=IdwFZD9mg_M:GzFj_m-p4Hk:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=IdwFZD9mg_M:GzFj_m-p4Hk:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=IdwFZD9mg_M:GzFj_m-p4Hk:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=IdwFZD9mg_M:GzFj_m-p4Hk:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=IdwFZD9mg_M:GzFj_m-p4Hk:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/rabidGadfly/blog/~4/IdwFZD9mg_M" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2013/03/how-to-load-external-data-into-a-fiddle/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://rabidgadfly.com/2013/03/how-to-load-external-data-into-a-fiddle/</feedburner:origLink></item>
		<item>
		<title>Plunk, Pen or Fiddle?</title>
		<link>http://feedproxy.google.com/~r/rabidGadfly/blog/~3/p4mMfac2ZHQ/</link>
		<comments>http://rabidgadfly.com/2013/03/plunk-pen-or-fiddle/#comments</comments>
		<pubDate>Thu, 14 Mar 2013 17:05:02 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[conversationStarter]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[codepen]]></category>
		<category><![CDATA[fiddle]]></category>
		<category><![CDATA[jsfiddle]]></category>
		<category><![CDATA[pen]]></category>
		<category><![CDATA[plunk]]></category>
		<category><![CDATA[plunker]]></category>

		<guid isPermaLink="false">http://rabidgadfly.com/?p=792</guid>
		<description><![CDATA[I’ve experienced some frustration recently with all of the big three code sandboxes: JSFiddle, Plunker, and CodePen. I’d originally picked Plunker because it provides the ability to create separate datasource files that can be used in my Plunks. This is &#8230; <a href="http://rabidgadfly.com/2013/03/plunk-pen-or-fiddle/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I’ve experienced some frustration recently with all of the big three code sandboxes: <a href="http://jsfiddle.net/" title="JSFiddle" target="_blank">JSFiddle</a>, <a href="http://plnkr.co" title="Plunker" target="_blank">Plunker</a>, and <a href="http://codepen.io/" title="CodePen" target="_blank">CodePen</a>. I’d originally picked Plunker because it provides the ability to create separate datasource files that can be used in my Plunks. This is extremely useful, especially when demonstrating how to load an external data source.</p>
<p>About a week ago while viewing my own post in <a href="http://www.appliness.com/" title="Appliness" target="_blank">Appliness</a> digital magazine (shameless plug) I noticed that I couldn’t access the source code in the embedded iFrame. I wasn’t sure if this was an oddity with Appliness so I made a mental note to check it out. </p>
<p>The very next day I received a comment from a visitor stating that they were having the same problem when viewing the site on their phone. Obviously, I had a problem. I want my code to be viewable on as many devices as possible so I started looking into alternatives. </p>
<h2>CodePen</h2>
<div style="float:right;"><a href="http://rabidgadfly.com/wp-content/uploads/2013/03/ferrari.jpg"><img src="http://rabidgadfly.com/wp-content/uploads/2013/03/ferrari.jpg" alt="ferrari" width="300" height="225" class="alignleft size-full wp-image-795" /></a></div>
<p>For looks, you can’t beat CodePen. It’s definitely the Ferrari of the bunch. Its sleek black skin and optional upgrades made me want to take it for a spin. The CodePen window is made up of four frames, HTML, CSS, JS, and the Output. Each code frame has its own set of additional features/libraries accessible via a small gear icon in the upper right corner.</p>
<p>CodePen’s additional features are very slick and useful. The HTML frame allows you to utilize three useful templating tools, Haml, Markdown and Slim, at the click of a button. CSS provides easy access to Less and Sass as well as some other oft-used CSS functionality, like reset. And JS frame applies clickable access to Coffeescript and Modernize, as well as allowing you to add any external library of your choosing. It also provides a useful link to cdnjs.com where you can find a CDN reference to just about any library yo can think of.</p>
<p><a href="http://rabidgadfly.com/wp-content/uploads/2013/03/codepen.jpg"><img src="http://rabidgadfly.com/wp-content/uploads/2013/03/codepen.jpg" alt="CodePen" width="600" height="376" class="aligncenter size-full wp-image-794" /></a></p>
<p>CodePen felt great, looked great, and provided optional upgrades. Unfortunately, once you take it out of the garage and park it in your driveway, i.e., embed it on your site, it doesn’t necessarily run great.</p>
<div style="float:right;"><a href="http://rabidgadfly.com/wp-content/uploads/2013/03/fiero.jpg"><img src="http://rabidgadfly.com/wp-content/uploads/2013/03/fiero.jpg" alt="fiero" width="300" height="204" class="alignright size-full wp-image-796" /></a></div>
<p>As a matter of fact, my Angular code which works when viewed on CodePen, did not work at all on my site. The Ferrari of sandboxes actually seems more like a Fiero with a Ferrari kit.</p>
<h2>JSFiddle</h2>
<div style="float:right;"><a href="http://rabidgadfly.com/wp-content/uploads/2013/03/minivan.jpg"><img src="http://rabidgadfly.com/wp-content/uploads/2013/03/minivan.jpg" alt="minivan" width="350" height="168" class="alignright size-full wp-image-802" /></a></div>
<p>JSFiddle seems to be the most widely-used sandbox. It’s the most utilitarian of the three&#8230;the minivan, if you will. Its looks are very basic, and while it claims the ability to apply different skins when embedded, the only skins available are “light” (light gray and white) and “presentation” (light gray and white with a gigantic font). You would think if there was a “light” there would also be a “dark”, right? Nope. This minivan only comes in gray. </p>
<p>Like CodePen, JSFiddle displays HTML, JS, CSS, and output frames. It provides access to a slew of libraries via a too-huge dropdown list. It also provides a second dropdown with esoteric options like “no wrap &#8211; in head”, which actually turns out to be quite important. The rest of the options are hidden in a vertical accordion.</p>
<p><a href="http://rabidgadfly.com/wp-content/uploads/2013/03/jsfiddle.jpg"><img src="http://rabidgadfly.com/wp-content/uploads/2013/03/jsfiddle.jpg" alt="jsfiddle" width="600" height="376" class="aligncenter size-full wp-image-801" /></a></p>
<p>The most important difference between CodePen and JSFiddle, however, is only apparent when it’s embedded. JSFiddle works and CodePen doesn’t. </p>
<h2>Plunker</h2>
<div style="float:right"><a href="http://rabidgadfly.com/wp-content/uploads/2013/03/buick.jpg"><img src="http://rabidgadfly.com/wp-content/uploads/2013/03/buick.jpg" alt="buick" width="350" height="183" class="alignright size-full wp-image-807" /></a></div>
<p>Plunkr is a little different than the others. It’s no Ferrari, but it’s no minivan either. I guess it’s a Buick. It’s looks are more modern than JSFiddles, but its options are almost non-existent. The window only has two frames: code and output. You create your own files rather than using dedicated HTML, JS, and CSS frames. While this means that you can’t look at all of your code at once, it actually lends to its flexibility. </p>
<p>With Plunkr you can create multiple files in the same project. This means you can test more abstractly, and easily swap functionality in and out. Your HTML head is in your code window making it easy to see what’s getting loaded. Being able to create your own files also means being able to create external datasources, which is fantastic for playing with dataloading functionality.</p>
<p><a href="http://rabidgadfly.com/wp-content/uploads/2013/03/plunker.jpg"><img src="http://rabidgadfly.com/wp-content/uploads/2013/03/plunker.jpg" alt="plunker" width="600" height="381" class="aligncenter size-full wp-image-808" /></a></p>
<p>The biggest problem with Plunker is the one I mentioned earlier. When it’s embedded, you can’t view the source files on mobile devices. </p>
<p>So, what do you drive, a Fiero/Ferrari, a minivan, or a Buick? Or something entirely different?</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=p4mMfac2ZHQ:cg7EmH_fqlM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=p4mMfac2ZHQ:cg7EmH_fqlM:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=p4mMfac2ZHQ:cg7EmH_fqlM:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=p4mMfac2ZHQ:cg7EmH_fqlM:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=p4mMfac2ZHQ:cg7EmH_fqlM:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=p4mMfac2ZHQ:cg7EmH_fqlM:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=p4mMfac2ZHQ:cg7EmH_fqlM:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=p4mMfac2ZHQ:cg7EmH_fqlM:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=p4mMfac2ZHQ:cg7EmH_fqlM:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/rabidGadfly/blog/~4/p4mMfac2ZHQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2013/03/plunk-pen-or-fiddle/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://rabidgadfly.com/2013/03/plunk-pen-or-fiddle/</feedburner:origLink></item>
		<item>
		<title>Super-Easy Angular Image Gallery</title>
		<link>http://feedproxy.google.com/~r/rabidGadfly/blog/~3/RPbolmTSsu4/</link>
		<comments>http://rabidgadfly.com/2013/03/super-easy-angular-image-gallery/#comments</comments>
		<pubDate>Tue, 05 Mar 2013 17:18:29 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[angularJS]]></category>
		<category><![CDATA[angular]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[gallery]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://rabidgadfly.com/?p=740</guid>
		<description><![CDATA[Check out this simple AngularJS example demonstrating the use of Angular, HTML5 and CSS3 to create a horizontally sliding image gallery.  <a href="http://rabidgadfly.com/2013/03/super-easy-angular-image-gallery/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div class="seriesmeta">This entry is part 9 of 9 in the series: <a href="http://rabidgadfly.com/series/angularjs-learning-series/" class="series-111" title="AngularJS Learning Series">AngularJS Learning Series</a></div><h2>Check it out!</h2>
<p>Learning <a href="http://angularjs.org/" title="AngularJS" target="_blank">Angular</a> has been a fantastic experience so far. I’ve been consistently surprised at the results I can get from a screenful of code. This week’s Image Gallery experiment was no different. Before I get into the particulars, let’s take a look at the finished product:</p>

<!-- iframe plugin v.2.5 wordpress.org/extend/plugins/iframe/ -->
<iframe src="http://embed.plnkr.co/MQwcpjMhq3DMTQrcRdy1" height="565" width="675" scrolling="no" class="iframe-class" frameborder="0"></iframe>
<p>If you check out the source app.js on that example you’ll notice that the JavaScript adds up to about 25 lines of code, half of which are dedicated to loading and setting the data source. Yes, there’s some CSS3 transition coolness thrown in, but even that is minimal.</p>
<h2>So How Does It Work?</h2>
<p>The gallery is made up of three sections: the main image, the caption, and the thumbnails. If you compare the main image section and the thumbnail section you’ll see that they’re very similar. The main difference being the size of the image how many of the image you can see:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;div class=&quot;mainimageshell&quot;&gt;
    &lt;div class=&quot;viewwindow&quot;&gt;
        &lt;ul id=&quot;fullscroller&quot; class=&quot;fullsizelist&quot; ng-style=&quot;listposition&quot; &gt;
            &lt;li ng-repeat=&quot;image in galleryData&quot;&gt;
                &lt;img id=&quot;fullsize&quot; class=&quot;large&quot; ng-src=&quot;{{image.image}}&quot; /&gt;
            &lt;/li&gt;
        &lt;/ul&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;div class=&quot;captionshell&quot;&gt;
    &lt;p class=&quot;caption&quot;&gt;{{selected.desc}}&lt;/p&gt;
&lt;/div&gt;

&lt;div class=&quot;thumbsshell&quot;&gt;
    &lt;div class=&quot;thumbswrapper&quot;&gt;
        &lt;ul&gt;
            &lt;li ng-repeat=&quot;image in galleryData&quot;&gt;
                &lt;div class=&quot;thumbwrapper&quot;&gt;
                    &lt;a ng-href=&quot;&quot; ng-click=&quot;scrollTo(image,$index)&quot;&gt;
                        &lt;img class=&quot;thumbnail&quot; ng-src=&quot;{{image.image}}&quot; /&gt;
                    &lt;/a&gt;
                &lt;/div&gt;
            &lt;/li&gt;
        &lt;/ul&gt;
    &lt;/div&gt;
&lt;/div&gt;
</pre>
<p>If you were to comment out the overflow line of the viewwindow class you would see all of the images lined up side by side, just like the thumbnails.</p>
<p>When iterating over the data using <a href="http://docs.angularjs.org/api/ng.directive:ngRepeat" title="Angular ngRepeat Directive" target="_blank">ng-repeat</a>, $index will reflect the zero-based index of each item. Since we’re looping over the same data, the index for both the large image and the thumbnail will be the same. This allows me to multiply the index by the width of the images to arrive at the new positioning for the large image list. Once I specify the new positioning, my CSS handles the <a href="http://www.w3schools.com/css3/css3_transitions.asp" title="CSS Transition" target="_blank">transition</a>, something like this:</p>
<pre class="brush: css; title: ; notranslate">
ul.fullsizelist{
    position:absolute;
    top:0;
    left:0;
    transition:  left .8s ease;
}
</pre>
<p>Thanks to Angular, notifying the DOM element of its new position is ultra-simple. If you take a look at the fullscroller UL inside the template you’ll see that it contains the Angular <a href="http://docs.angularjs.org/api/ng.directive:ngStyle" title="AngularJS ngStyle Directive" target="_blank">ng-style</a> directive and that it’s bound to the listposition property. Listposition is updated in the scrollTo function every time a thumbnail is clicked and any change is immediately reflected in the view:</p>
<pre class="brush: jscript; title: ; notranslate">
// Scroll to appropriate position based on image index and width
$scope.scrollTo = function(image,ind) {
    $scope.listposition = {left:(IMAGE_WIDTH * ind * -1) + &quot;px&quot;};
    $scope.selected = image;
}
</pre>
<p>In addition to modifying the viewwindow position, the scrollTo function also assigns the currently selected item to $scope.selected. If you look at the template you’ll see that caption is rendering “{{selected.desc}}”. When $scope.selected is changed, the caption will automatically change with it. </p>
<h2>Full Disclosure</h2>
<p>My original idea was to fade out the old image and fade in the new image when a thumbnail was clicked. This worked great on Chrome, but Firefox would flash the image on screen once loaded and wouldn’t transition in properly. It also required transition end listeners, which at the moment are <a href="http://stackoverflow.com/questions/2794148/css3-transition-events" title="TransitionEnd not quite ready for primetime" target="_blank">not standard across browsers</a>. That meant separate listeners for each browser engine. </p>
<p>The whole thing was becoming a hassle and the code was getting unruly. That’s when I made the decision to switch to a slider and it worked out great. Point being, don’t be afraid to experiment or refactor. Oftentimes the best coding decisions are born out of a change in approach.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=RPbolmTSsu4:qbSfSyDm9kw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=RPbolmTSsu4:qbSfSyDm9kw:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=RPbolmTSsu4:qbSfSyDm9kw:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=RPbolmTSsu4:qbSfSyDm9kw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=RPbolmTSsu4:qbSfSyDm9kw:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=RPbolmTSsu4:qbSfSyDm9kw:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=RPbolmTSsu4:qbSfSyDm9kw:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=RPbolmTSsu4:qbSfSyDm9kw:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=RPbolmTSsu4:qbSfSyDm9kw:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/rabidGadfly/blog/~4/RPbolmTSsu4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2013/03/super-easy-angular-image-gallery/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<series:name><![CDATA[AngularJS Learning Series]]></series:name>
	<feedburner:origLink>http://rabidgadfly.com/2013/03/super-easy-angular-image-gallery/</feedburner:origLink></item>
		<item>
		<title>Angular and XML? No Problem!</title>
		<link>http://feedproxy.google.com/~r/rabidGadfly/blog/~3/u70kATMhJ-o/</link>
		<comments>http://rabidgadfly.com/2013/02/angular-and-xml-no-problem/#comments</comments>
		<pubDate>Wed, 20 Feb 2013 17:58:58 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[angularJS]]></category>
		<category><![CDATA[angular]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://rabidgadfly.com/?p=701</guid>
		<description><![CDATA[Angular likes JSON, and can you blame it? Angular is a JavaScript toolset and JSON is JavaScript Object Notation, a native brethren. XML, on the other hand, is tag-based markup...a foreign language to Angular. The key to overcoming any language gap is to have a translator. This post discusses the usefulness and implementation of a transformResponse function to load XML into an Angular app. An example is included. <a href="http://rabidgadfly.com/2013/02/angular-and-xml-no-problem/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div class="seriesmeta">This entry is part 7 of 9 in the series: <a href="http://rabidgadfly.com/series/angularjs-learning-series/" class="series-111" title="AngularJS Learning Series">AngularJS Learning Series</a></div><h2>The Finished Product</h2>
<p>JSON is a native object to AngularJS so working solely with JSON examples is easy. In the real world, however, you&#8217;ll probably need to deal with other types of data sources, like XML. Before I get too wordy, let&#8217;s start with what you&#8217;re really here for&#8230;the example:</p>

<!-- iframe plugin v.2.5 wordpress.org/extend/plugins/iframe/ -->
<iframe src="http://embed.plnkr.co/Hpx8GPHt0IqKADj8K1Qc" width="100%" height="365px" scrolling="no" class="iframe-class" frameborder="0"></iframe>
<h2>The Explanation</h2>
<p>While the finished product looks like the result of 15 minutes of coding, I have to admit that it took me significantly longer to figure out. If you search the Angular <a href="http://docs.angularjs.org/guide/" title="AngularJS Developer Guide" target="_blank">Developer Guide</a> or <a href="http://docs.angularjs.org/api" title="AngularJS API" target="_blank">API</a> for &#8220;XML&#8221; you&#8217;re going to come up woefully absent of useful results. Googling won&#8217;t get you much further. As frustration began to set in, I started thinking about what made loading an XML file more difficult than loading a JSON file. The answer is: not much!</p>
<h2>Bridging the Language Gap</h2>
<p>Angular likes JSON, and can you blame it? Angular is a JavaScript toolset and JSON is JavaScript Object Notation, a native brethren. XML, on the other hand, is tag-based markup&#8230;a foreign language to Angular. What I needed was a way to make Angular understand what XML was trying to communicate.</p>
<p>The key to overcoming any language gap is to have a translator. If there were a way to translate XML to JSON before handing it to the application then I could eliminate the language gap, and the problem.</p>
<p>A quick search for xml converters turned up multiple results. I chose <a title="X2JS Project Home" href="http://code.google.com/p/x2js/" target="_blank">Abdulla Abdurakhmano&#8217;s X2JS</a> library because it was the first one I came across, it was lightweight, and it was pretty easy to use.</p>
<p>The code required to perform the translation is short and simple. Provide the library with XML, tell it which method to use, and receive JSON in return:</p>
<pre class="brush: jscript; title: ; notranslate">
function(xml) {
 var x2js = new X2JS();
 var json = x2js.xml_str2json( xml );
 return json;
}
</pre>
<h2>Where to Stick It</h2>
<p>Now that I had a solution to the language gap I needed to decide where to implement it. Angular&#8217;s $http service conveniently applies transformation functions for both requests and responses. These functions apply transformations to data when it is sent and received, and they can be overridden.</p>
<p>Using the X2JS conversion code as a transformResponse function it was simple to get the $http service to read in XML and return JSON to the application, effectively creating the translator I needed. The results look something like this:</p>
<pre class="brush: jscript; title: ; notranslate">
angular.module('myApp.service',[]).
    factory('DataSource', ['$http',function($http){
       return {
           get: function(callback){
                $http.get(
                    'data.xml',
                    {transformResponse:function(data) {
                    	// convert the data to JSON and provide
                    	// it to the success function below
						var x2js = new X2JS();
						var json = x2js.xml_str2json( data );
						return json;
						}
					}
                ).
                success(function(data, status) {
					// send the converted data back
					// to the callback function
                    callback(data);
                })
           }
       }
    }]);
    
angular.module('myApp',['myApp.service']);

var AppController = function($scope,DataSource) {
    
    //This is the callback function
    setData = function(data) {
        $scope.dataSet = data;
    }
        
    DataSource.get(setData);
    
}
</pre>
<p>That&#8217;s really all there is to it! The example above will retrieve an xml file named &#8220;data.xml&#8221;, convert it to JSON, and assign the results to $scope.dataSet.</p>
<h2>The Caveat</h2>
<p>XML comes in all shapes and sizes. Some use attributes, others don&#8217;t, and many use a combination of both. Some XML files use a proper header, others are just fragments. Your application will likely require tweaking to get the data into the shape that your application requires. Always read the docs, read the comments, and experiment.</p>
<p>The example at the beginning of this post is a great starting point. Fork it and experiment with different libraries or XML formats.</p>
<p>Keep on Coding!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=u70kATMhJ-o:BzbMnU-2s-k:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=u70kATMhJ-o:BzbMnU-2s-k:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=u70kATMhJ-o:BzbMnU-2s-k:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=u70kATMhJ-o:BzbMnU-2s-k:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=u70kATMhJ-o:BzbMnU-2s-k:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=u70kATMhJ-o:BzbMnU-2s-k:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=u70kATMhJ-o:BzbMnU-2s-k:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=u70kATMhJ-o:BzbMnU-2s-k:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=u70kATMhJ-o:BzbMnU-2s-k:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/rabidGadfly/blog/~4/u70kATMhJ-o" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2013/02/angular-and-xml-no-problem/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<series:name><![CDATA[AngularJS Learning Series]]></series:name>
	<feedburner:origLink>http://rabidgadfly.com/2013/02/angular-and-xml-no-problem/</feedburner:origLink></item>
		<item>
		<title>Angular Intro to Modules, Services, Factories, and Filtering</title>
		<link>http://feedproxy.google.com/~r/rabidGadfly/blog/~3/PPGjkkTlRTY/</link>
		<comments>http://rabidgadfly.com/2013/02/angular-intro-to-modules-services-factories-and-filtering/#comments</comments>
		<pubDate>Tue, 12 Feb 2013 17:20:12 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[angularJS]]></category>
		<category><![CDATA[factory]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[service]]></category>

		<guid isPermaLink="false">http://rabidgadfly.com/?p=689</guid>
		<description><![CDATA[This week's self-imposed Angular assignment was to create a small app that would dynamically filter a list of data using an input field as search criteria. I chose to base the app on my son's homework assignment and use United States states and capitals.  This short and simple AngularJS example introduces the use of modules, services, factories and filtering.  <a href="http://rabidgadfly.com/2013/02/angular-intro-to-modules-services-factories-and-filtering/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div class="seriesmeta">This entry is part 5 of 9 in the series: <a href="http://rabidgadfly.com/series/angularjs-learning-series/" class="series-111" title="AngularJS Learning Series">AngularJS Learning Series</a></div><h2>The Assignment</h2>
<p>This week&#8217;s self-imposed Angular assignment was to create a small app that would dynamically filter a list of data using an input field as search criteria. I chose to base the app on my son&#8217;s homework assignment and use United States states and capitals.</p>
<p>In my previous examples I used Controllers for all functions and assignments. For simple non-critical applications the configuration works well, but for larger real-world applications a more abstract approach makes sense. Enter Angular Modules.</p>
<h2>The Basics</h2>
<p><a title="Angular module" href="http://docs.angularjs.org/guide/module" target="_blank">Modules</a> initialize Angular applications and wire together its services, filters, directives, etc. This makes the code portable, easier to debug, and easier to unit test.</p>
<p>To keep things simple, I only used a service in this example. The service is a gofer, responsible for carrying out any requests made by the controller. The controller sets scope properties and behaviors and handles calls from the <a title="Angular template" href="http://docs.angularjs.org/guide/dev_guide.templates" target="_blank">template</a>.</p>
<p>Here&#8217;s a basic module, service, and controller in Angular:</p>
<pre class="brush: jscript; title: ; notranslate">
angular.module('myApp.service',[]);
angular.module('myApp',['myApp.service']);
var StatesController = function($scope) {}
</pre>
<p>On the first line is a service named &#8216;myApp.service&#8217;. Note that the dot is not necessary, nor is using the app name as a prefix. I could have named it &#8216;gofer&#8217; if I wanted. The important part is that I let the main application module know the name, which brings me to line 2, the main module.</p>
<p>The main module names the app and gives it a a comma delimited reference to services, filters, etc. that can be referenced. If I defined a filter named &#8216;myApp.filter&#8217; my module definition would have been: &#8220;angular.module(&#8216;myApp&#8217;,['myApp.service'<strong>,'myApp.filter'</strong>]);&#8221;. The module name, &#8220;myApp&#8221;, will be used in my ngApp directive in the template.</p>
<p>Line 3 is the shell of a controller definition which will be directly accessible by the template. While it wouldn&#8217;t do anything at this point, we could hook those three lines up to a template and assign myApp to the ngApp directive without error.</p>
<h2>Let&#8217;s Get Some Data!</h2>
<p>As with most applications, we&#8217;ll need access to data. My data source is a <a href="http://en.wikipedia.org/wiki/Json" target="_blank">JSON</a> file that looks like this:</p>
<pre class="brush: jscript; title: ; notranslate">
[
    {&quot;name&quot;:&quot;Alabama&quot;, &quot;capital&quot;:&quot;Montgomery&quot;,&quot;abbreviation&quot;:&quot;AL&quot;},
    {&quot;name&quot;:&quot;Alaska&quot;, &quot;capital&quot;:&quot;Juneau&quot;,&quot;abbreviation&quot;:&quot;AK&quot;},
    {&quot;name&quot;:&quot;Arizona&quot;, &quot;capital&quot;:&quot;Phoenix&quot;,&quot;abbreviation&quot;:&quot;AZ&quot;},
    {&quot;name&quot;:&quot;Arkansas&quot;, &quot;capital&quot;:&quot;Little Rock&quot;,&quot;abbreviation&quot;:&quot;AR&quot;},
    ...
]
</pre>
<p>I need a way to create a resource object out of that data so I can interact with it. Angular&#8217;s ngResource module provides exactly what I need in its <a title="Angular resource" href="http://docs.angularjs.org/api/ngResource.$resource" target="_blank">$resource</a> service.</p>
<blockquote><p>NOTE: The ngResource module is NOT in the base angular.js file. To use it you must load angular-resource.js in addition to angular.js. If you get an error in your debugging console that says &#8220;Uncaught Error: No module: ngResource&#8221;, chances are you forgot to load angular-resource.js. You do use a <a href="http://www.1stwebdesigner.com/design/web-development-tools-elements-techniques/" target="_blank">developer tools</a>, right?</p></blockquote>
<p>To retrieve the resource I utilized a method used to create objects in Angular called a factory. When I put the factory method inside my service, and then provide my Controller with a reference to it, I can use it in my controller to set a scoped property, like this:</p>
<pre class="brush: jscript; title: ; notranslate">
angular.module('myApp.service',['ngResource']).
    factory('States', function($resource){
        return $resource('states.json', {},{
            get: {method: 'GET', isArray:true}
        });
    });

angular.module('myApp',['myApp.service']);

var StatesController = function($scope,States) {
    $scope.stateData = States.get();
};
</pre>
<p>So, what changed? First, I gave my service a reference to Angular&#8217;s ngResource module. That will give me the ability to use the $resource service for my factory allowing me to interact with my data source, &#8220;states.json&#8221;. Notice that the factory has a name, &#8220;States&#8221; which I provide to my Controller. From there I can access actions inside the factory, such as &#8220;get&#8221;, &#8220;save&#8221;, and &#8220;delete&#8221;.</p>
<p>Now, if I create a template referencing the controller I can display the data using my stateData property. Check out the source code here:<br />

<!-- iframe plugin v.2.5 wordpress.org/extend/plugins/iframe/ -->
<iframe src="http://embed.plnkr.co/zXGpgCkUl8cF5rzbIWYP" width="100%" height="300" scrolling="no" class="iframe-class" frameborder="0"></iframe></p>
<h2>Make Something Angulary Happen</h2>
<p>We now have a working module, a service, a factory, a controller, and data. Time to do something slick with it. Building off the html above, Inside my StatesController DIV I&#8217;m going to delete the current {{stateData}} dump and replace it with something a little easier to read:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;ul class=&quot;states&quot;&gt;
   &lt;li&gt;
      &lt;div class=&quot;resultwrapper&quot;&gt;
         &lt;span class=&quot;title&quot;&gt;{{state.name}}&lt;/span&gt;&lt;br&gt;
         &lt;span class=&quot;bold&quot;&gt;Abbreviation:&lt;/span&gt; {{state.abbreviation}}&lt;br&gt;
         &lt;span class=&quot;bold&quot;&gt;Capital:&lt;/span&gt; {{state.capital}}
      &lt;/div&gt;
   &lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>Using ng-repeat and an unordered list, my state information now displays in a style-able list. Unfortunately, a couple of my states are not in alphabetical order. This can be fixed easily by telling the repeater to order it using a built-in filter module named orderBy after my iterator:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;ul class=&quot;states&quot;&gt;
   &lt;li ng-repeat=&quot;state in stateData | filter:criteria | orderBy:'name'&quot;&gt;
       &lt;div class=&quot;resultwrapper&quot;&gt;
          &lt;span class=&quot;title&quot;&gt;{{state.name}}&lt;/span&gt;&lt;br&gt;
          &lt;span class=&quot;bold&quot;&gt;Abbreviation:&lt;/span&gt; {{state.abbreviation}}&lt;br&gt;
          &lt;span class=&quot;bold&quot;&gt;Capital:&lt;/span&gt; {{state.capital}}
       &lt;/div&gt;
   &lt;/li&gt;
&lt;/ul&gt;
</pre>
<blockquote><p>Note that &#8216;name&#8217; is a string, not a reference. I could have also defined a property for it in the controller and used it with the orderBy.</p></blockquote>
<p>Now that they&#8217;re in alphabetical order I want to be able to search them. This was done by adding a simple input and assigning it an ng-model of &#8216;critera&#8217;, then giving that to the ng-repeat filter. Angular uses the value entered into the criteria field as a filter for the stateData array. Throw in a style sheet and you have a pretty nifty widget using a very minimal amount of code.</p>
<h2>The Result</h2>

<!-- iframe plugin v.2.5 wordpress.org/extend/plugins/iframe/ -->
<iframe src="http://embed.plnkr.co/BixOgwEu66Hzco6rZJqt" width="100%" height="500" scrolling="no" class="iframe-class" frameborder="0"></iframe>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=PPGjkkTlRTY:yr5vknWiw1w:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=PPGjkkTlRTY:yr5vknWiw1w:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=PPGjkkTlRTY:yr5vknWiw1w:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=PPGjkkTlRTY:yr5vknWiw1w:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=PPGjkkTlRTY:yr5vknWiw1w:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=PPGjkkTlRTY:yr5vknWiw1w:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=PPGjkkTlRTY:yr5vknWiw1w:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=PPGjkkTlRTY:yr5vknWiw1w:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=PPGjkkTlRTY:yr5vknWiw1w:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/rabidGadfly/blog/~4/PPGjkkTlRTY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2013/02/angular-intro-to-modules-services-factories-and-filtering/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<series:name><![CDATA[AngularJS Learning Series]]></series:name>
	<feedburner:origLink>http://rabidgadfly.com/2013/02/angular-intro-to-modules-services-factories-and-filtering/</feedburner:origLink></item>
		<item>
		<title>Responsive Form Validation with AngularJS and HTML5</title>
		<link>http://feedproxy.google.com/~r/rabidGadfly/blog/~3/FchCHJKJjkg/</link>
		<comments>http://rabidgadfly.com/2013/01/form-validation-with-angularjs-and-html5/#comments</comments>
		<pubDate>Tue, 22 Jan 2013 15:17:13 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[angularJS]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://rabidgadfly.com/?p=677</guid>
		<description><![CDATA[This AngularJS example demonstrates how HTML5 and AngularJS can work together to provide a modern approach to form submission and validation without lengthy JavaScript validation algorithms, cumbersome CSS, or page refreshes. <a href="http://rabidgadfly.com/2013/01/form-validation-with-angularjs-and-html5/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div class="seriesmeta">This entry is part 6 of 9 in the series: <a href="http://rabidgadfly.com/series/angularjs-learning-series/" class="series-111" title="AngularJS Learning Series">AngularJS Learning Series</a></div><p>This AngularJS example demonstrates how HTML5 and AngularJS can work together to provide a modern approach to form submission and validation without lengthy JavaScript validation algorithms, cumbersome CSS, or page refreshes.</p>
<p>Note that there are multiple ways to present and submit a form using HTML5 and AngularJS. Your implementation should depend on the needs of your application. The method I use here does not perform an actual submit. Instead, when the Submit button is clicked it calls a function that updates a visitorInfo object. Any action can be performed when the visitorInfo object is updated by modifying the update function in VisitorFormController in app.js.</p>
<p>The example provides immediate feedback based on the data entered into the input fields. Every input field has been flagged as &#8220;required&#8221; and you can watch the debugging info to see the status change dynamically as each input field is populated.</p>
<p>[There is a JSFiddle embedded in this post. Please follow the link below or go to the site to see this JSFiddle.]</p><p><a class="ia-jsfiddle-link" href="http://jsfiddle.net/rabidGadfly/CUzbs">View this on JSFiddle</a></p>
<p>Let&#8217;s take a closer look at the email section to see how this is done:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;span class=&quot;label&quot;&gt;Email:&lt;/span&gt;
&lt;input type=&quot;email&quot; name=&quot;email&quot; placeholder=&quot;Email&quot; required=&quot;&quot; /&gt;
&lt;span class=&quot;valid&quot;&gt;?&lt;/span&gt;

</pre>
<p>The first line is simply the label that is show before the input field. The &#8220;label&#8221; class lets me apply some styling to keep it on the same line as the input field, make it bold, etc. No magic there.</p>
<p>The input field has several attributes. <em><strong>Name</strong></em> gives us a means of referring to that specific field. <em><strong>Type</strong></em> defaults to &#8220;text&#8221; but we&#8217;ve given it the HTML5 type of &#8220;email&#8221;. Doing so implements validation rules, such as requiring an <strong>&amp;</strong> and a domain type (like .COM). It also causes responsive mobile devices to present different UI. For example, assigning a type of <strong>email</strong> will cause &#8220;.COM&#8221; to appear on keyboards of many mobile devices.</p>
<p>The <a href="http://docs.angularjs.org/api/ng.directive:ngModel">ngModel</a> directive links the input field to a scope property, in this case <strong>visitorInfo.email</strong>. <strong>visitorInfo</strong> is an object that holds all of the form properties. Notice that each input field model includes <strong>visitorInfo</strong> before the property name. You can watch <strong>visitorInfo</strong> populate in the debugging info as you fill in the form.</p>
<p><em><strong>Placeholder</strong></em> is a new input attribute that allows you to define a short data entry hint that will appear inside the input field. The hint disappears when the user starts entering text but will reappear if the text is deleted. Placeholder text does not get submitted as form data.</p>
<p>Finally, there is the <em><strong>required</strong></em> attribute that defines the field as one that must be filled in for the form to be considered valid.</p>
<p>The <strong>span</strong> below the input field contains a checkmark that is not visible when the page first loads. The AngularJS <a href="http://docs.angularjs.org/api/ng.directive:ngShow" target="_blank">ngShow</a> directive has an evaluation in it that will only allow the span to be visible when the field passes email field passes validation rules.</p>
<p>Negative feedback is provided courtesy of CSS and AngularJS. Enter a value in the First Name field and then delete it. The field background will change to red. If you look in style.css you&#8217;ll see the following section:</p>
<pre class="brush: css; title: ; notranslate">
input.ng-invalid.ng-dirty {
	background-color:red;
}
</pre>
<p>ng-invalid and ng-dirty automatically get assigned as classes based on the input field state. If the field contents are invalid then the input field will be dynamically assigned the ng-invalid class. We can use that class to style the field in certain circumstances as I did above. Pretty slick! See the <a href="http://docs.angularjs.org/api/ng.directive:form" target="_blank">AngularJS API</a> for more information on these class assignments.</p>
<p>Finally, check out the Submit and Restore buttons. The Submit button&#8217;s job is to update the <strong>visitorInfo</strong> object. The restore button restores all of the field data to the last submitted value.</p>
<p>Both buttons react to the state of the form. The submit button will enable and turn green when the entire form has been filled out with valid information. The restore button enables when the form data differs from the stored <strong>visitorInfo</strong> object data.</p>
<p>This functionality is done using a combination of AngularJS&#8217;s <a href="http://docs.angularjs.org/api/ng.directive:ngClick" target="_blank">ngClick</a> and <a href="http://docs.angularjs.org/api/ng.directive:ngDisabled" target="_blank">ngDisabled</a> directives:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;button ng-click=&quot;reset()&quot; ng-disabled=&quot;isUnchanged(visitorInfo)&quot;&gt;RESTORE&lt;/button&gt;
&lt;button class=&quot;submitbtn&quot; ng-click=&quot;update(visitorInfo)&quot; ng-disabled=&quot;valForm.$invalid || isUnchanged(visitorInfo)&quot;&gt;SUBMIT&lt;/button&gt;
</pre>
<p>ngDisabled contains an evaluation. If the evaluation is true then ngDisabled will also be set to true, making the buttons un-clickable. If they evaluate to false then the buttons will become enabled. Once they are enable, they can be clicked and the clicks will be handled by the functions that are referenced in the ngClick directives.</p>
<p>All in all it was very easy. The code itself is MUCH shorter than this post, which is a testament to the simplicity of AngularJS and HTML5 (or it could be just an indication that I&#8217;m too wordy.) In either case, I&#8217;m using that line as an opportunity to wrap this post up.</p>
<p>As always, check out the code on Plunkr. Fork it, edit it, experiment with it. It&#8217;s the best way to learn.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=FchCHJKJjkg:T9GS8rWQynM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=FchCHJKJjkg:T9GS8rWQynM:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=FchCHJKJjkg:T9GS8rWQynM:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=FchCHJKJjkg:T9GS8rWQynM:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=FchCHJKJjkg:T9GS8rWQynM:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=FchCHJKJjkg:T9GS8rWQynM:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=FchCHJKJjkg:T9GS8rWQynM:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=FchCHJKJjkg:T9GS8rWQynM:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=FchCHJKJjkg:T9GS8rWQynM:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/rabidGadfly/blog/~4/FchCHJKJjkg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2013/01/form-validation-with-angularjs-and-html5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[AngularJS Learning Series]]></series:name>
	<feedburner:origLink>http://rabidgadfly.com/2013/01/form-validation-with-angularjs-and-html5/</feedburner:origLink></item>
		<item>
		<title>Create an Easy AngularJS Menu</title>
		<link>http://feedproxy.google.com/~r/rabidGadfly/blog/~3/RQ3N1Yjt4Kc/</link>
		<comments>http://rabidgadfly.com/2013/01/create-an-easy-angularjs-menu/#comments</comments>
		<pubDate>Tue, 08 Jan 2013 17:32:26 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[angularJS]]></category>
		<category><![CDATA[menu]]></category>

		<guid isPermaLink="false">http://rabidgadfly.com/?p=665</guid>
		<description><![CDATA[This entry is part 4 of 9 in the series: AngularJS Learning SeriesMy goal for this AngularJS experiment was to create a multi-level menu with a hide-away submenu, fed from an external data source. The sub-menu should appear when its &#8230; <a href="http://rabidgadfly.com/2013/01/create-an-easy-angularjs-menu/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div class="seriesmeta">This entry is part 4 of 9 in the series: <a href="http://rabidgadfly.com/series/angularjs-learning-series/" class="series-111" title="AngularJS Learning Series">AngularJS Learning Series</a></div><p>My goal for this <a href="http://angularjs.org" title="AngularJS" target="_blank">AngularJS</a> experiment was to create a multi-level menu with a hide-away submenu, fed from an external data source. The sub-menu should appear when its parent is clicked. As with my other AngularJS examples, this turned out to be a very simple task involving minimal code. </p>
<p>[There is a JSFiddle embedded in this post. Please follow the link below or go to the site to see this JSFiddle.]</p><p><a class="ia-jsfiddle-link" href="http://jsfiddle.net/rabidGadfly/f8ea6">View this on JSFiddle</a></p>
<p>One directive in the example that I hadn&#8217;t used before was <a href="http://docs.angularjs.org/api/ng.directive:ngStyle" title="AngularJS ngStyle Directive" target="_blank">ngStyle</a> which facilitates dynamic style assignment. I use it here to position the submenu under the appropriate parent item. The directive is assigned to the ul block, and when the parent item is clicked, a function is called that modifies the scoped &#8216;subLeft&#8217; property, something like this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;ul&gt;
   &lt;li ng-click=&quot;setStyle()&quot;&gt;menu item&lt;/li&gt;
&lt;/ul&gt;
&lt;ul ng-style=&quot;subLeft&quot;&gt;
   &lt;li&gt;submenu item&lt;/li&gt;
&lt;/ul&gt;
</pre>
<pre class="brush: jscript; title: ; notranslate">
$scope.setStyle = function() {
   $scope.subLeft = {'padding-left':'80px'};
}
</pre>
<p>One hurdle I had to overcome was that <a href="http://docs.angularjs.org/api/ng.directive:ngClick" title="AngularJS ngClick" target="_blank">ng-click</a> only takes an Angular <a href="http://docs.angularjs.org/guide/expression" title="AngularJS Expressions" target="_blank">expression</a>, which does not use JavaScript eval() to evaluate. I wanted to send the id of the element that was clicked so I could derive its coordinates as a way of knowing where to place the submenu. Without the use of JavaScript I was unable to do that. </p>
<p>In the interest of keeping the example simple, I ended up sending the Angular iterator <a href="http://docs.angularjs.org/api/ng.directive:ngRepeat" title="AngularJS ngRepeat" target="_blank">index</a> instead of the element id. Since all of my menu items are the same width it was a matter of multiplying the index by that width to arrive at the correct positioning. Problem solved!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=RQ3N1Yjt4Kc:9DvUTZgfbWk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=RQ3N1Yjt4Kc:9DvUTZgfbWk:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=RQ3N1Yjt4Kc:9DvUTZgfbWk:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=RQ3N1Yjt4Kc:9DvUTZgfbWk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=RQ3N1Yjt4Kc:9DvUTZgfbWk:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=RQ3N1Yjt4Kc:9DvUTZgfbWk:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=RQ3N1Yjt4Kc:9DvUTZgfbWk:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=RQ3N1Yjt4Kc:9DvUTZgfbWk:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=RQ3N1Yjt4Kc:9DvUTZgfbWk:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/rabidGadfly/blog/~4/RQ3N1Yjt4Kc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2013/01/create-an-easy-angularjs-menu/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<series:name><![CDATA[AngularJS Learning Series]]></series:name>
	<feedburner:origLink>http://rabidgadfly.com/2013/01/create-an-easy-angularjs-menu/</feedburner:origLink></item>
		<item>
		<title>XSLT Gotcha When Combining Attribute Sets</title>
		<link>http://feedproxy.google.com/~r/rabidGadfly/blog/~3/D5tSfEYaD6c/</link>
		<comments>http://rabidgadfly.com/2013/01/xslt-gotcha-combining-attribute-sets/#comments</comments>
		<pubDate>Thu, 03 Jan 2013 18:01:40 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[XML]]></category>
		<category><![CDATA[xslt]]></category>
		<category><![CDATA[attribute-set]]></category>
		<category><![CDATA[style]]></category>
		<category><![CDATA[use-attribute-sets]]></category>

		<guid isPermaLink="false">http://rabidgadfly.com/?p=656</guid>
		<description><![CDATA[Discussion of the use of style as an attribute in an XSLT attribute set, and the unintended consequences when combining it with other attribute sets using use-attribute-sets.  <a href="http://rabidgadfly.com/2013/01/xslt-gotcha-combining-attribute-sets/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I made my first foray into <a href="http://www.w3schools.com/xsl/default.asp" title="XSLT at W3Schools" target="_blank">XSLT</a> territory recently. Quick definition from W3Schools:</p>
<blockquote><p>
&#8220;XSL stands for EXtensible Stylesheet Language, and is a style sheet language for XML documents. XSLT stands for XSL Transformations.&#8221;
</p></blockquote>
<p>Overall the experience was a good one. It was very easy to figure out how to display an XML document in an HTML report format. It was also very easy to style the report using <a href="http://www.w3schools.com/xsl/el_attributeset.asp" title="xslt attribute-sets" target="_blank">attribute sets</a>. Essentially, attribute sets allow you to define styles for different elements in your document. Elements use &#8220;use-attribute-sets&#8221; to define the sets that should be applied. For example:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;xsl:attribute-set name=&quot;bodystyle&quot;&gt;
    &lt;xsl:attribute name=&quot;bgcolor&quot;&gt;
        #cccccc
    &lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;

&lt;xsl:template match=&quot;report&quot;&gt;
    &lt;html&gt;
        &lt;body xsl:use-attribute-sets=&quot;bodystyle&quot;&gt;
            &lt;xsl:apply-templates select=&quot;headerData&quot;/&gt;
            &lt;xsl:apply-templates select=&quot;reportData&quot;/&gt;
        &lt;/body&gt;
    &lt;/html&gt;
&lt;/xsl:template&gt;
</pre>
<p>The code above would make the body background color #cccccc. Works great. But what if I wanted to set a property that isn&#8217;t an attribute of the element. What if I want to set the font color, for example. There is no &#8220;color&#8221; attribute for body. In this case, the style attribute can be used:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;xsl:attribute-set name=&quot;defaultfontcolor&quot;&gt;
    &lt;xsl:attribute name=&quot;style&quot;&gt;
        color:#111;
    &lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;

&lt;xsl:template match=&quot;report&quot;&gt;
    &lt;html&gt;
        &lt;body xsl:use-attribute-sets=&quot;defaultfontcolor&quot;&gt;
            &lt;xsl:apply-templates select=&quot;headerData&quot;/&gt;
            &lt;xsl:apply-templates select=&quot;reportData&quot;/&gt;
        &lt;/body&gt;
    &lt;/html&gt;
&lt;/xsl:template&gt;
</pre>
<p>So far, so good. The cool thing about attribute sets is that they can be combined, too. Let&#8217;s say I want to combine the two examples above and set the body color and font color at the same time. I could define both in the same attribute set, but I want to use the font color elsewhere without the bgcolor. This can be done easily:</p>
<pre class="brush: xml; title: ; notranslate">

&lt;xsl:attribute-set name=&quot;bodystyle&quot;&gt;
    &lt;xsl:attribute name=&quot;bgcolor&quot;&gt;
        #cccccc
    &lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;

&lt;xsl:attribute-set name=&quot;defaultfontcolor&quot;&gt;
    &lt;xsl:attribute name=&quot;style&quot;&gt;
        color:#111;
    &lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;

&lt;xsl:template match=&quot;report&quot;&gt;
    &lt;html&gt;
        &lt;body xsl:use-attribute-sets=&quot;bodystyle defaultfontcolor&quot;&gt;
            &lt;xsl:apply-templates select=&quot;headerData&quot;/&gt;
            &lt;xsl:apply-templates select=&quot;reportData&quot;/&gt;
        &lt;/body&gt;
    &lt;/html&gt;
&lt;/xsl:template&gt;
</pre>
<p>As you can see in the body tag I&#8217;ve listed both attribute sets, separated by a space. This works great!</p>
<p>Now here&#8217;s the gotcha. The last attribute set in the list will override previous style definitions of the same attribute. Normally, this isn&#8217;t a problem&#8230;as long as you&#8217;re not using the style attribute in more than one set. While the style attribute can define more than one element property, &#8220;style&#8221; itself is the attribute. Therefore, if you try to combine two attribute sets that both define &#8220;style&#8221;, only the last one will be implemented, regardless of whether they define different properties. </p>
<p>For example, although the code below defines the same styles as the one above, only the defaultfontcolor attribute set will be implemented. This is because both sets define the same attribute: &#8220;style&#8221;. </p>
<pre class="brush: xml; title: ; notranslate">

&lt;xsl:attribute-set name=&quot;bodystyle&quot;&gt;
    &lt;xsl:attribute name=&quot;style&quot;&gt;
        background: #ccc;
    &lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;

&lt;xsl:attribute-set name=&quot;defaultfontcolor&quot;&gt;
    &lt;xsl:attribute name=&quot;style&quot;&gt;
        color:#111;
    &lt;/xsl:attribute&gt;
&lt;/xsl:attribute-set&gt;

&lt;xsl:template match=&quot;report&quot;&gt;
    &lt;html&gt;
        &lt;body xsl:use-attribute-sets=&quot;bodystyle defaultfontcolor&quot;&gt;
            &lt;xsl:apply-templates select=&quot;headerData&quot;/&gt;
            &lt;xsl:apply-templates select=&quot;reportData&quot;/&gt;
        &lt;/body&gt;
    &lt;/html&gt;
&lt;/xsl:template&gt;
</pre>
<p>It doesn&#8217;t matter that one defines background and the other defines color. It only matters that they both set the &#8220;style&#8221; attribute. And because defaultfontcolor is last in the use-attribute-sets list, its definition is used over bodystyle. </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=D5tSfEYaD6c:G1BVwgyIcTE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=D5tSfEYaD6c:G1BVwgyIcTE:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=D5tSfEYaD6c:G1BVwgyIcTE:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=D5tSfEYaD6c:G1BVwgyIcTE:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=D5tSfEYaD6c:G1BVwgyIcTE:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=D5tSfEYaD6c:G1BVwgyIcTE:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=D5tSfEYaD6c:G1BVwgyIcTE:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=D5tSfEYaD6c:G1BVwgyIcTE:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=D5tSfEYaD6c:G1BVwgyIcTE:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/rabidGadfly/blog/~4/D5tSfEYaD6c" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2013/01/xslt-gotcha-combining-attribute-sets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://rabidgadfly.com/2013/01/xslt-gotcha-combining-attribute-sets/</feedburner:origLink></item>
		<item>
		<title>AngularJS Data Loading and Assignment</title>
		<link>http://feedproxy.google.com/~r/rabidGadfly/blog/~3/PjXp_2jqHvw/</link>
		<comments>http://rabidgadfly.com/2012/12/angularjs-data-loading-and-assignment/#comments</comments>
		<pubDate>Wed, 26 Dec 2012 17:48:11 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[angularJS]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[json]]></category>

		<guid isPermaLink="false">http://rabidgadfly.com/?p=635</guid>
		<description><![CDATA[Incredibly simple example describing how to use the AngularJS $http service to load data from a JSON file, iterate through all the data, and dynamically display detail data from a clicked list item.  <a href="http://rabidgadfly.com/2012/12/angularjs-data-loading-and-assignment/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div class="seriesmeta">This entry is part 4 of 9 in the series: <a href="http://rabidgadfly.com/series/angularjs-learning-series/" class="series-111" title="AngularJS Learning Series">AngularJS Learning Series</a></div><p>My goal with today&#8217;s <a href="http://angularjs.org" title="AngularJS" target="_blank">AngularJS</a> experiment is to load data from a <a href="http://en.wikipedia.org/wiki/JSON" title="JSON Definition" target="_blank">JSON</a> file, iterate through all the data, and dynamically display detail data from a clicked list item. This proved to be incredibly simple and ended up taking less than 50 lines of code, including comments!</p>
<p>The data loading is done using the AngularJS <a href="http://docs.angularjs.org/api/ng.$http" title="AngularJS http directive" target="_blank">$http</a> service. In this example, the data object is assigned to $scope.artists when it has been successfully loaded:</p>
<pre class="brush: jscript; title: ; notranslate">
$http.get('artists.json').success(function(data) {
   $scope.artists = data;
});
</pre>
<p>Once the data is loaded I can iterate over it using the AngularJS <a href="http://docs.angularjs.org/api/ng.directive:ngClick" title="AngularJS ngClick Directive" target="_blank">ng-click</a> directive. The code below loops over each record in the artists object that I loaded above. It displays the artistName property found in each artist and then assigned a function (setSelectedArtist) that will be executed when the name is clicked.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;ul&gt;
	&lt;li ng-repeat=&quot;artist in artists&quot;&gt;
    	&lt;a href ng-click='setSelectedArtist(artist)'&gt;{{artist.artistName}}&lt;/a&gt;&lt;/li&gt;
	&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>When an artist name is clicked, its artist object is passed to the setSelectedArtist function found in ArtistsController. setSelectedArtist assigns the artist to the scoped selectedArtist property. When that occurs, page references to selectedArtist are updated to reflect the new assignment:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;div class=&quot;detailimagewrapper&quot;&gt;
    &lt;img class=&quot;detailimage&quot; src=&quot;{{selectedArtist.img}}&quot; &gt;
&lt;/div&gt;
&lt;p&gt;{{selectedArtist.description}}&lt;/p&gt;
</pre>
<p>Check out the example on Plunker. It&#8217;s well-commented and easy to modify. Try adding the artist&#8217;s genre to the detail section. Or add a new field, like recordLabel or dateFormed.</p>

<!-- iframe plugin v.2.5 wordpress.org/extend/plugins/iframe/ -->
<iframe height="400" width="100%" src="http://embed.plnkr.co/R6u0QYAyKj3IvRGEtWp8" scrolling="no" class="iframe-class" frameborder="0"></iframe>
<p>This post is barely the tip of the iceberg regarding what the AngularJS $http service offers. Check out the <a href="http://docs.angularjs.org/guide/" title="AngularJS Developer Guide" target="_blank">documentation</a> to learn more.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=PjXp_2jqHvw:FszjvQfcQgU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=PjXp_2jqHvw:FszjvQfcQgU:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=PjXp_2jqHvw:FszjvQfcQgU:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=PjXp_2jqHvw:FszjvQfcQgU:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=PjXp_2jqHvw:FszjvQfcQgU:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=PjXp_2jqHvw:FszjvQfcQgU:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=PjXp_2jqHvw:FszjvQfcQgU:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=PjXp_2jqHvw:FszjvQfcQgU:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=PjXp_2jqHvw:FszjvQfcQgU:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/rabidGadfly/blog/~4/PjXp_2jqHvw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2012/12/angularjs-data-loading-and-assignment/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<series:name><![CDATA[AngularJS Learning Series]]></series:name>
	<feedburner:origLink>http://rabidgadfly.com/2012/12/angularjs-data-loading-and-assignment/</feedburner:origLink></item>
		<item>
		<title>AngularJS Fun With Scopes</title>
		<link>http://feedproxy.google.com/~r/rabidGadfly/blog/~3/fG9cgFrmiBk/</link>
		<comments>http://rabidgadfly.com/2012/12/angularjs-fun-with-scopes/#comments</comments>
		<pubDate>Tue, 18 Dec 2012 12:39:38 +0000</pubDate>
		<dc:creator>rabidgadfly</dc:creator>
				<category><![CDATA[angularJS]]></category>
		<category><![CDATA[inheritance]]></category>
		<category><![CDATA[scope]]></category>

		<guid isPermaLink="false">http://rabidgadfly.com/?p=616</guid>
		<description><![CDATA[AngularJS scopes go hand and hand with the DOM (Document Object Model). DOM objects within a controller reference rely first on their controller counterparts for their property assignments. This example demonstrates scopes and scope inheritance and provides fields that you can manipulate to immediately see how scope is handled within AngularJS. <a href="http://rabidgadfly.com/2012/12/angularjs-fun-with-scopes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div class="seriesmeta">This entry is part 3 of 9 in the series: <a href="http://rabidgadfly.com/series/angularjs-learning-series/" class="series-111" title="AngularJS Learning Series">AngularJS Learning Series</a></div><p>This is the third in a series of posts detailing my experience learning AngularJS. This post and its accompanying example discusses the handling of scope. <a href="http://angularjs.org/" title="AngularJS" target="_blank">AngularJS</a> scopes go hand and hand with the DOM (Document Object Model). DOM objects within a controller reference rely first on their controller counterparts for their property assignments.</p>
<p>The example below includes three controllers: Limericks, Limerick1 and Limerick2. Limerick1 and Limerick2 use identical property names, but each are given unique values. If you look at index.html you&#8217;ll see two DIVs with ng-controller references to their respective controller definitions in app.js. Because they&#8217;re separate DOM objects, they can use the same property names locally.</p>
<p>Try changing the &#8220;Title&#8221; and &#8220;Field&#8221; values within each of the limericks. Notice that only one limerick changes even though its property names are identical to the other limerick. (Sidenote: the example scrolls down quite a bit. To view it on a full page, <a href="http://plnkr.co/edit/nuZfXuJ7Q8bhBOGDHNfl" target="_blank">open it up in plunker</a> and click the eye icon on the right to view the rendered page)</p>
<p>[There is a JSFiddle embedded in this post. Please follow the link below or go to the site to see this JSFiddle.]</p><p><a class="ia-jsfiddle-link" href="http://jsfiddle.net/rabidGadfly/Bkcp7">View this on JSFiddle</a></p>
<p>AngularJS controllers aren&#8217;t limited to local property definitions, though. They also inherit from parent scopes. Look at the DIV that references the Limericks controller. Notice that it wraps around both Limerick1 and Limerick2. This allows Limerick1/2 to inherit from Limericks. </p>
<p>To illustrate inheritance, {{author}} is defined only in Limericks but it&#8217;s used within all three controller objects. Try changing the value in the &#8220;Global Author&#8221; field to see how it changes in all three scopes.</p>
<p>But wait, there&#8217;s more! Inherited properties can be modified locally without affecting the parent value. Like {{authors}}, {{pageTitle}} is also only defined in the Limericks controller. Its value is &#8220;Pretty Bad Limericks&#8221;. The first instance of it on the page is outside of Limerick1 and Limerick2. The second instance is within Limerick1 and the third is within Limerick2. </p>
<p>Try changing the first instance by modifying the value in the &#8220;Parent pageTitle&#8221; field. Notice that both pageTitles change. Now try changing the value in the &#8220;Inherited pageTitle&#8221; field. Only the local value changes. Limericks1 {{pageTitle}} is now uncoupled from its parent value since it has been assigned a local one. If you change the first instance again you&#8217;ll notice that the Limerick2 instance is still inheriting but Limerick1 is not.</p>
<p>For more information on AngularJS scopes, see the <a href="http://docs.angularjs.org/guide/scope" title="AngularJS Scopes" target="_blank">dev documentation</a>.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=fG9cgFrmiBk:p_mZHlR9qKc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=fG9cgFrmiBk:p_mZHlR9qKc:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=fG9cgFrmiBk:p_mZHlR9qKc:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=fG9cgFrmiBk:p_mZHlR9qKc:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=fG9cgFrmiBk:p_mZHlR9qKc:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=fG9cgFrmiBk:p_mZHlR9qKc:l6gmwiTKsz0"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=l6gmwiTKsz0" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=fG9cgFrmiBk:p_mZHlR9qKc:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?i=fG9cgFrmiBk:p_mZHlR9qKc:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/rabidGadfly/blog?a=fG9cgFrmiBk:p_mZHlR9qKc:TzevzKxY174"><img src="http://feeds.feedburner.com/~ff/rabidGadfly/blog?d=TzevzKxY174" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/rabidGadfly/blog/~4/fG9cgFrmiBk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://rabidgadfly.com/2012/12/angularjs-fun-with-scopes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[AngularJS Learning Series]]></series:name>
	<feedburner:origLink>http://rabidgadfly.com/2012/12/angularjs-fun-with-scopes/</feedburner:origLink></item>
	</channel>
</rss>
