AngularJs overview



AngularJs overview

0 0


ng-overview-slides


On Github owencraig / ng-overview-slides

AngularJs overview

(cool people would call it an ng Overview)
  • Remember to tell people to ask questions at any time
  • Speak slowly, you have an accent here

Luckily, we're not cool people

Scot Goodhart and Owen Craig

Lifelong nerds, we both work as consultants for Rightpoint Consulting with almost 20 years combined experience in server side .Net and a more recent deep dive into client side development specialising in AngularJs

  • A bit of a chat about rightpoint and that we're hiring?

What is AngularJs?

Angular is a development platform for building mobile and desktop web applications

http://angular.io

Seriously awesome, it brings all of the structure and sanity from server side frameworks to the front end

Owen Craig

I love the modularity, the separation of concerns. Also, love Directives; they are like lego pieces for building web apps.

Scot Goodhart
  • A good time to ask who is how familiar with angular
  • Talk about how Angular is an MVC framework (need to expand on what MVC is if need be). In its current form it's more of an MVVM framework.

Why?

  • Super fast prototyping
  • Two way data binding
  • In built SOC
  • Dependency injection by default
  • An awesome community
  • Backed by Google
  • A simple structure model for large applications
  • A lot of stuff for free
  • Why does this provide value? Why should I pay attention?

So, what do we get?

ViewModels/Views

  • Really simple templating to bind your markup to data
  • An easy separation of concerns between logic and display

Controller Text: Hello, World

  • 42
  • 28
  • 15
  • 9
  • 180
  • 99
Markup
<div class="_angularOverview" ng-controller="naiveController as vm">
	<p><span class="label">Controller Text:</span> {{vm.text}}</p>
	<ul>
		<li ng-repeat="int in vm.ints track by $index">{{int}}</li>
	</ul>
</div>
Javascript
angular.module("angularOverview").controller('naiveController', function(){
	var vm = this;
	vm.text = 'Hello, World';
	vm.ints = [42,28,15,9,180,99];
});

Two way data Binding

  • Makes user input handling super easy
  • Allows you to deal with your application code rather than dealing with DOM manipulation
Input text:
Array[2] Value:

Controller Text: Hello, World

  • 42
  • 28
  • 15
  • 9
  • 180
  • 99
Markup
<div class="_angularOverview" ng-controller="naiveController as vm">
	<div>
		<label for="twoWayText">Input text:</label>
		<input type="text" id="twoWayText" ng-model="vm.text">
	</div>
	<div>
		<label for="arrayBind">Array[2] Value:</label>
		<input type="number" id="arrayBind" ng-model="vm.ints[2]">
	</div>
	<p><span class="label">Controller Text:</span> {{vm.text}}</p>
	<ul>
		<li ng-repeat="int in vm.ints track by $index">{{int}}</li>
	</ul>
</div>

Directives

  • Decouples your controller code from the DOM
  • Encapsulates repeated Elements/controls across your application
  • Say you've got a few places in your app where you show the same thing, rather than copy and pasting the code you can create a reusable component
Input text:
Array[2] Value:

Controller Text: Hello, World

  • 42
  • 28
  • 15
  • 9
  • 180
  • 99
<div class="_angularOverview" ng-controller="naiveController as vm">
	<div>
		<label for="twoWayText">Input text:</label>
		<input type="text" id="twoWayText" ng-model="vm.text">
	</div>
	<div>
		<label for="arrayBind">Array[2] Value:</label>
		<input type="number" id="arrayBind" ng-model="vm.ints[2]">
	</div>
	<p><span class="label">Controller Text:</span> {{vm.text}}</p>
	<list-numbers numbers="vm.ints"></list-numbers>
</div>
angular.module("angularOverview").directive('listNumbers', function () {
	return {
		restrict: 'E',
		scope: {
			numbers: '='
		},
		template:'<ul><li ng-repeat="int in numbers">{{int}}</li></ul>'
	};
});

Services/Factories

  • Increases encapsulation
  • allows your controllers/viewmodels to remain light
  • Aids code reuse

Dependency Injection

  • Built in to angular
  • Increases ease of unit testing
  • Makes following the SRP super simple
  • Do we need to give a quick overview of DI/IoC here?
  • this could be a talk in and of its own
Input text:
Array[2] Value:

Controller Text: Hello, World

  • 42
  • 28
  • 15
  • 9
  • 180
  • 99
angular.module("angularOverview").controller('diController', function(IntegralService){
	var vm = this;
	vm.text = 'Hello, World';
	vm.ints = IntegralService.getSomeInts();
});

angular.module("angularOverview").factory('IntegralService', function () {
	return {
		getSomeInts: getSomeInts
	};

	function getSomeInts(){
		return [42,28,15,9,180,99];
	}
});

Modules

  • Every app in angular is a module
  • Modules can be injected into each other
  • Allows for common libraries to be built and passed around
  • Combined with a model oriented architecture, allows switching on and off of application functionality

Promises

  • Helps avoid the pyramid of doom
  • Makes async code a little nicer
  • Gives explicit error handling for callbacks

Some Included Helpers

  • $http
  • $resource
  • $filter
  • $route

Some Code!

Some easy pitfalls

  • Relying only on scope/not using 'controller as'
  • It's not a silver bullet
  • Angular 2 is on the horizon

Thank you

Resources

Us

Rightpoint

We're hiring: http://rightpoint.com/careers

AngularJs overview (cool people would call it an ng Overview) Remember to tell people to ask questions at any time Speak slowly, you have an accent here