Passie: Betere software door testen
"When you develop in Angular, you are developing in a better browser!"
"Angular is what the web browser would have been, had it been designed for applications"
<input id="toggleShowHide" type="checkbox">
<div id=”specialParagraph”>
This content will disappear and reappear if you click the checkbox above
</div>
<script>
$(function() {
function toggle() {var isChecked = $('#toggleShowHide').is(':checked');
var specialParagraph = $('#specialParagraph');if (isChecked) { specialParagraph.show(); }
else { specialParagraph.hide(); }
}
$('#toggleShowHide').change(function() {
toggle();
});
toggle();
});
</script>
<input ng-model="showSpecial" type="checkbox">
<div ng-show=”showSpecial”> This content will disappear and reappear if you click the checkbox above </div>
"Conceptually, Directives are NOT packaged JQuery"
Vaak eerst één module per app.
angular.module('ggdodApp', []);
Module per feature
angular.module('ggdodApp', ['ngAnimate', 'ngRoute', 'ngResource']);
app.js
angular.module('ggdodApp', []);
index.html
<!DOCTYPE HTML> <html ng-app="ggdodApp"> <head>
<title>Gino Draait Door op Dinsdag </title>
</head>
<body>
<h1> Dit Gino Draait Door op Dinsdag</h1>
<script src="scripts/vendor/angular/angular.min.js">
<script src="scripts/app.js"></script>
</body>
</html>
$scope.person = {
firstName: 'Jan'
lastName: 'Progger'
}
controller.js
<h1> {{ person.firstname }} </h1>
template.html
scripts/controllers/main.js
"Expose model objects and methods to the View"
angular.module('ggdodApp')
.controller('MainCtrl', function ($scope) {
$scope.person = {
firstName: 'Jan'
lastName: 'Progger'
}
});
views/main.html
<div ng-controller="MainCtrl as main">
<p> {{ main.person.firstname }} {{ main.person.firstname }} </p>
</div>
scripts/controllers/main.js
angular.module('ggdodApp') .controller('MainCtrl', function () {
this.person = { firstName: 'Jan' lastName: 'Progger' }
});
angular.module('ggdodApp', ['ngRoute']) .config(function ($routeProvider) { $routeProvider .when('/', { templateUrl: 'views/main.html', controller: 'MainCtrl' })
.when('/person/:name', { templateUrl: 'views/person.html', controller: 'PersonCtrl' }) .otherwise({ redirectTo: '/' }); });
scripts/services/person.js
angular.module('ggdodApp').factory('Person', function(){
var personFactory = {};
var person = {
firstName: 'Jan',
lastName: 'Progger
}
personFactory.get = function(){
return person;
}
return personFactory;
});
scripts/services/constants.js
angular.module('ggdodApp').constant('BEDRIJF', 'Gino B.V.');
angular.module('ggdodApp').constant('ANSWER', 42);
scripts/controllers/main.js
angular.module('ggdodApp').controller('MainCtrl',
function(BEDRIJF, ANSWER){
console.log('Bedrijf is ' + BEDRIJF);
console.log('The all knowing answer is: ' + ANSWER);
}
<h1> {{ person.firstname }} <h1>
<h1 ng-bind="person.firstname> </h1>
/scripts/app.js
angular.module('ggdodApp', ['ngRoute', 'ngResource', 'ui-bootstrap']);
/scripts/controllers/main.js
angular.module('ggdodApp')
.controller('MainCtrl', function($scope, $routeParam, Person){
$scope.person = Person.get();
$scope.save = function(person){
Person.save(person);
}
});
<ul>
<li ng-repeat="person in persons | orderBy: 'lastname'">
{{ person.firstname }}
, {{ person.lastname | uppercase}}
</li>
</ul>
"A way to teach HTML new Tricks."
Element
<ng-view></ng-view>
Attribute
<div ng-view></div>
Class
<div class="ng-view"><div>
angular.module('ggdod', ['ngAnimate']);
yo angular demo