Created by Tom Wilson / @twilson63
WHOAMI
President of Jack Russell Software, a Division of CareKinesis
Technology Vision, Software Architecture, Developer Training
Head Instructor for CHS CodeCamp - http://chscodecamp.com
Teach: AngularJS, NodeJS, CouchDb, and DevTools
CoderDojo CHS http://coderdojochs.github.io/
Champion - NodeCopter Pilot Instructor
Our clients continued to ask/demand for richer user experiences.
http://fistfuloftalent.com/wp-content/uploads/2012/06/angry-computer-large-500x320.jpgJQuery event model was becoming unmaintainable.
We needed to test our JavaScript in a sane efficient way.
http://blog.algoworks.com/wp-content/uploads/2013/09/Software-testing-trends-2013.jpgWe wanted a JavaScript Framework that would be fun and productive.
http://tippingback.com/wp-content/uploads/2012/11/How-to-have-fun-advice-from-the-social-skills-self-help-blog-tipping-back.jpgAngularJS is built around the belief that declarative programming should be used for building UIs and wiring software components, while imperative programming is excellent for expressing business logic. The framework adapts and extends traditional HTML to better serve dynamic content through two-way data-binding that allows for the automatic synchronization of models and views. As a result, AngularJS deemphasizes DOM manipulation and improves testability.
hhttp://en.wikipedia.org/wiki/Angular_JS<!doctype html>
<html ng-app>
<head>
<script src="http://code.angularjs.org/1.2.0-rc.2/angular.min.js"></script>
</head>
<body>
<p ng-init=" name='World' ">Hello {{name}}!</p>
</body>
</html>
See the Pen %= penName %> by Tom Wilson (@twilson63) on CodePen
<html ng-app>
<head>
<script src="http://code.angularjs.org/1.2.0-rc.2/angular.min.js"></script>
</head>
<body>
<input ng-model="name">
<p>Hello {{name}}!</p>
</body>
</html>
See the Pen %= penName %> by Tom Wilson (@twilson63) on CodePen
Dependency Injection (DI) is a software design pattern that deals with how code gets hold of its dependencies.
angular.module('app')
.controller('MainCtrl', function($scope, $http, $location) {
...
});
angular.module('App', [])
.controller('HomeCtrl', function($window) {
$window.document.write('Hello World');
});
See the Pen %= penName %> by Tom Wilson (@twilson63) on CodePen
angular.module('myModule', [])
.factory('notify', function($window) {
var msgs = [];
return function(msg) {
msgs.push(msg);
if (msgs.length == 3) {
$window.alert(msgs.join("\n"));
msgs = [];
}
};
}]);
.controller('MainCtrl', function($scope, notify) {
notify('Hello');
notify('World');
notify('GoodBye');
});
});
See the Pen %= penName %> by Tom Wilson (@twilson63) on CodePen
Services are Singletons
ngRepeat
<html ng-app>
<head><title>HelloWorld</title></head>
<body>
<div ng-init=" items=[1,2,3,4] "></div>
<ul>
<li ng-repeat="item in items">
{{item}}
</li>
<script src="http://code.angularjs.org/1.2.0-rc.2/angular.min.js"></script>
</body>
</html>
See the Pen %= penName %> by Tom Wilson (@twilson63) on CodePen
ngClick
<html ng-app>
<head><title>HelloWorld</title></head>
<body>
<div ng-controller="Main">
<div ng-init=" items=[1,2,3,4] "></div>
<button ng-click="alert()">Click</button>
</div>
<script src="http://code.angularjs.org/1.2.0-rc.2/angular.min.js"></script>
</body>
</html>
See the Pen %= penName %> by Tom Wilson (@twilson63) on CodePen
Understanding the Directive
angular.module('app')
.directive('myDirective', function() {
return {
restrict: 'EAC',
scope: true,
transclude: false,
replace: true,
compile: ...
link: ...
templateUrl: ...
controller: ...
}
});
See the Pen %= penName %> by Tom Wilson (@twilson63) on CodePen
Build your own
angular.module('directive', []).directive('contenteditable', function() {
return {
require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
// view -> model
elm.on('blur', function() {
scope.$apply(function() {
ctrl.$setViewValue(elm.html());
});
});
// model -> view
ctrl.$render = function(value) {
elm.html(value);
};
// load init value from DOM
ctrl.$setViewValue(elm.html());
}
};
});
See the Pen %= penName %> by Tom Wilson (@twilson63) on CodePen
Community
http://ngmodules.org/