SlideShare a Scribd company logo
1 of 37
Download to read offline
Zukunftssichere Anwendungen
mit AngularJS 1.x entwickeln
Christian Janz (@c_janz)
christian.janz@bridging-it.de
Wer steht hier vorne?
Christian Janz
Consultant bei BridgingIT GmbH in Mannheim
Interesse: Architektur und Entwicklung von
Geschäftsanwendungen mit modernen Frameworks
AngularJS 1.x? Warum nicht Angular 2?
“Angular 2 is currently in Developer Preview. We recommend using Angular 1.X
for production applications.”
https://angular.io/docs/ts/latest/
Dilemma?
1.x 2
Entwickle die Anwendung mit AngularJS 1.x,
aber mit Angular 2 im Blick
Lösungsansatz
Neuerung in Angular 2
Eine Auswahl :-)
Neue Template-Syntax
1. <li *ng-for="#hero of heroes" (click)="onSelect(hero)">
2. <span class="badge">{{hero.id}}</span> {{hero.name}}
3. </li>
ES 2015 Support / TypeScript
● Angular 2 wird in TypeScript entwickelt
● Verwendet ES 2015 Module
○ Framework wird modularer
○ Kein eigenes Modulsystem mehr (angular.
module(...))
● Einsatz von Decorators für Metadaten
1. import {bootstrap, Component} from
'angular2/angular2';
2.
3. @Component({
4. selector: 'my-app',
5. template: '<h1>My First Angular 2 App</h1>'
6. })
7. class AppComponent { }
8.
9. bootstrap(AppComponent);
Verbesserte Dependency Injection
● Hierarchische Dependency Injection Container
● Matching der Abhängigkeiten über Typ, nicht über Name
Komponentenbasiert
● Keine Standalone Controller mehr (ng-controller=””)
● Kein $scope mehr
● @Component: Komponente (≅ AngularJS 1.x Direktiven)
● @Directive: Komponente ohne View
Neuer Router
● Komponentenbasiert
● Deutlich mächtiger als ng-route
● Parallelentwicklung für Angular 2 und Angular 1.x
○ Gleiche API
○ Soll Migration erleichtern
TypeScript
TypeScript und EcmaScript
ES 5
ES 2015
TypeScript
ES 2015 Module
Import, Export
http://www.2ality.com/2014/09/es6-modules-final.html
// lib/math.js
export function sum(x, y) {
return x + y;
}
export const pi = 3.141593;
// app.js
import * as math from "lib/math";
alert("2π = " + math.sum(math.pi, math.pi));
// otherApp.js
import {sum, pi} from "lib/math";
alert("2π = " + sum(pi, pi));
Default Export
http://www.2ality.com/2014/09/es6-modules-final.html
//------ myFunc.js ------
export default function foo() { ... };
//------ main1.js ------
import myFunc from 'myFunc';
// import { default as foo } from 'myFunc';
myFunc();
Module Loader API
http://www.2ality.com/2014/09/es6-modules-final.html
System.import('lib/debug').then(function(m) {
// do something with the module m
});
Browser-Support
Kein Browser unterstützt bisher nativ ES 2015 Module
⇒ Bibliotheken/Tools notwendig
Refactoring Patterns
Services & Bootstrapping
Services
angular.module('myTestApp')
.factory('gitHubService', function ($http) {
function buildRepoUrl(userId) {
return
'https://api.github.com/users/'
+ userId + '/repos';
}
function getRepos(userId) {
return $http.get(buildRepoUrl(userId))
.then(function (result) {
return result.data;
});
}
return {
getRepos: getRepos
}
});
export default class GitHubService {
constructor(private $http: angular.IHttpService) {
}
private buildRepoUrl(userId: string): string {
return `https://api.github.com/users/${userId}
/repos`;
}
public getRepos(userId: string): any {
return this.$http.get(this.buildRepoUrl(userId))
.then(function (result) {
return result.data;
});
}
}
Bootstrapping
//app.js
angular.module('myTestApp', []);
------------
//index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Old Code</title>
</head>
<body ng-app="myTestApp">
<script src="bower_components/angular/angular.js"
></script>
<script src="app.js"></script>
<script src="github.service.js"></script>
</body>
</html>
//app.ts
import angular = require('angular');
import GitHubService from './github.service';
let module = angular.module('myTestApp', [])
.service('gitHubService', GitHubService);
angular.bootstrap(window.document.body, [module.name]);
------------
//index.html
<!DOCTYPE html>
<html lang="en">
<head>...</head>
<body>
<script src="jspm_packages/system.js"></script>
<script src="config.js"></script>
<script>
System.import('lib/app');
</script>
</body>
</html>
Refactoring Patterns
Controller & Direktiven
ng-controller durch Komponente ersetzen Teil 1: Controller Aliasing
//index.html
<body ng-app="myTestApp">
<main ng-controller="MainCtrl">
<ul ng-controller="RepoListCtrl">
<li ng-repeat="repo in repos"
ng-click="selectRepo(repo)">
{{repo}}
</li>
</ul>
<div>
Selected Repo: {{selectedRepo}}
</div>
</main>
</body>
//index.html
<body ng-app="myTestApp">
<main ng-controller="MainCtrl as mainCtrl">
<ul ng-controller="RepoListCtrl as repoListCtrl">
<li ng-repeat="repo in repoListCtrl.repos"
ng-click="mainCtrl.selectRepo(repo)">
{{repo}}
</li>
</ul>
<div>
Selected Repo: {{mainCtrl.selectedRepo}}
</div>
</main>
</body>
//index.html
<body ng-app="myTestApp">
<main ng-controller="MainCtrl as mainCtrl">
<ul ng-controller="RepoListCtrl as repoListCtrl">
<li ng-repeat="repo in repoListCtrl.repos"
ng-click="mainCtrl.selectRepo(repo)">
{{repo}}
</li>
</ul>
<div>
Selected Repo: {{mainCtrl.selectedRepo}}
</div>
</main>
</body>
ng-controller durch Komponente ersetzen Teil 2: Direktive erstellen
//index.html
<body ng-app="myTestApp">
<main-app></main-app>
</body>
//main.directive.js
angular.module('myTestApp')
.directive('mainApp', function() {
return {
scope: true,
templateUrl: 'mainApp.template.html'
}
})
//mainApp.template.html
<main ng-controller="MainCtrl as mainCtrl">
<ul ng-controller="RepoListCtrl as repoListCtrl">
<li ng-repeat="repo in repoListCtrl.repos"
ng-click="mainCtrl.selectRepo(repo)">
{{repo}}
</li>
</ul>
<div>
Selected Repo: {{mainCtrl.selectedRepo}}
</div>
</main>
ng-controller durch Komponente ersetzen Teil 3: Root ng-controller entfernen
//index.html
<body ng-app="myTestApp">
<main-app></main-app>
</body>
//main.directive.js
angular.module('myTestApp')
.directive('mainApp', function() {
return {
scope: true,
templateUrl: 'mainApp.template.html'
}
})
//mainApp.template.html
<main ng-controller="MainCtrl as mainCtrl">
<ul ng-controller="RepoListCtrl as repoListCtrl">
<li ng-repeat="repo in repoListCtrl.repos"
ng-click="mainCtrl.selectRepo(repo)">
{{repo}}
</li>
</ul>
<div>
Selected Repo: {{mainCtrl.selectedRepo}}
</div>
</main>
//index.html
<body ng-app="myTestApp">
<main-app></main-app>
</body>
//main.directive.js
angular.module('myTestApp')
.directive('mainApp', function() {
return {
scope: true,
controller: 'MainCtrl',
controllerAs: 'mainCtrl',
templateUrl: 'mainApp.template.html'
}
})
//mainApp.template.html
<main>
<ul ng-controller="RepoListCtrl as repoListCtrl">
<li ng-repeat="repo in repoListCtrl.repos"
ng-click="mainCtrl.selectRepo(repo)">
{{repo}}
</li>
</ul>
<div>
Selected Repo: {{mainCtrl.selectedRepo}}
</div>
</main>
ng-controller durch Komponente ersetzen Teil 4: Direktive und Controller kombinieren
//main.directive.js
angular.module('myTestApp')
.directive('mainApp', function() {
return {
scope: true,
controller: 'MainCtrl',
controllerAs: 'mainCtrl',
templateUrl: 'mainApp.template.html'
}
})
//main.ctrl.js
angular.module('myTestApp')
.controller('MainCtrl', function () {
this.userId = 'bridgingIT';
this.selectedRepo = '';
this.selectRepo = function(repo) {
this.selectedRepo = repo;
}
});
//main.directive.js
angular.module('myTestApp')
.directive('mainApp', function() {
function MainCtrl() {
this.userId = 'bridgingIT';
this.selectedRepo = '';
this.selectRepo = function(repo) {
this.selectedRepo = repo;
}
}
return {
scope: true,
controller: MainCtrl,
controllerAs: 'mainCtrl',
templateUrl: 'mainApp.template.html'
}
});
ng-controller durch Komponente ersetzen Teil 4b: Direktive in TypeScript
//main.directive.js
angular.module('myTestApp')
.directive('mainApp', function() {
function MainCtrl() {
this.userId = 'bridgingIT';
this.selectedRepo = '';
this.selectRepo = function(repo) {
this.selectedRepo = repo;
}
}
return {
scope: true,
controller: MainCtrl,
controllerAs: 'mainCtrl',
templateUrl: 'mainApp.template.html'
}
});
//main.directive.ts
class MainController {
public userId: string = 'bridgingIT';
public selectedRepo: string = '';
public onSelectRepo(repo: string) {
this.selectedRepo = repo;
}
}
export default () => {
return {
scope: {},
controller: MainController,
controllerAs: 'mainCtrl',
templateUrl: 'mainApp.template.html',
bindToController: true,
}
}
//app.ts
import angular = require('angular');
import MainComponent from './main.directive;
let module = angular.module('myTestApp', [])
.directive('mainApp', MainComponent)
angular.bootstrap(window.document.body, [module.name]);
ng-controller durch Komponente ersetzen Teil 5: Teilkomponente extrahieren
//mainApp.template.html
<main>
<ul ng-controller="RepoListCtrl as repoListCtrl">
<li ng-repeat="repo in repoListCtrl.repos"
ng-click="mainCtrl.selectRepo(repo)">
{{repo}}
</li>
</ul>
<div>
Selected Repo: {{mainCtrl.selectedRepo}}
</div>
</main>
//mainApp.template.html
<main>
<repo-list></repo-list>
<div>
Selected Repo: {{mainCtrl.selectedRepo}}
</div>
</main>
// repoList.directive.js
angular.module('myTestApp')
.directive('repoList', function () {
function RepoListCtrl($scope, gitHubService) {
var that = this;
$scope.$watch('mainCtrl.userId', function (newUserId) {
gitHubService.getRepos(newUserId)
.then(function (result) {
that.repos = result.map(function (repo) {
return repo.name;
});
});
});
}
return {
scope: true,
controller: RepoListCtrl,
controllerAs: 'repoListCtrl',
templateUrl: 'repoList.template.html'
}
});
ng-controller durch Komponente ersetzen Teil 5: Input und Output Parameter
// repoList.directive.js
angular.module('myTestApp')
.directive('repoList', function () {
function RepoListCtrl($scope, gitHubService) {
var that = this;
$scope.$watch('mainCtrl.userId', function (newUserId) {
gitHubService.getRepos(newUserId)
.then(function (result) {
that.repos = result.map(function (repo) {
return repo.name;
});
});
});
}
return {
scope: true,
controller: RepoListCtrl,
controllerAs: 'repoListCtrl',
templateUrl: 'repoList.template.html'
}
});
// repoList.template.html
<ul>
<li ng-repeat="repo in repoListCtrl.repos"
ng-click="mainCtrl.selectRepo(repo)">
{{repo}}
</li>
</ul>
//mainApp.template.html
<main>
<repo-list></repo-list>
<div>
Selected Repo: {{mainCtrl.selectedRepo}}
</div>
</main>
ng-controller durch Komponente ersetzen Teil 5: Input und Output Parameter
// repoList.directive.js
angular.module('myTestApp')
.directive('repoList', function () {
function RepoListCtrl($scope, gitHubService) {
var that = this;
$scope.$watch('repoListCtrl.userId', function (newUserId) {
gitHubService.getRepos(newUserId)
.then(function (result) {
that.repos = result.map(function (repo) {
return repo.name;
});
});
});
this.selectRepo = function(repo) {
that.onSelectRepo({repo: repo});
}
}
return {
scope: {
userId: '=',
onSelectRepo: '&'
},
bindToController: true,
controller: RepoListCtrl,
controllerAs: 'repoListCtrl',
templateUrl: 'repoList.template.html'
}
});
// repoList.template.html
<ul>
<li ng-repeat="repo in repoListCtrl.repos"
ng-click="repoListCtrl.selectRepo(repo)">
{{repo}}
</li>
</ul>
//mainApp.template.html
<main>
<repo-list
user-id="mainCtrl.userId"
on-select-repo="mainCtrl.selectRepo(repo)">
</repo-list>
<div>
Selected Repo: {{mainCtrl.selectedRepo}}
</div>
</main>
https://github.com/cjanz/angular-refactoring-patterns
Bitte noch mal langsam...
ngUpgrade
AngularJS 1.x und Angular 2 in einer Anwendung
https://github.com/angular/ngUpgrade
Fazit
AngularJS 1.x ist nicht tot
● Einige Ansätze aus Angular 2 können auch in
AngularJS 1.x genutzt werden
○ ES 2015 Module
○ Komponenten
● TypeScript erleichtert Refactoring
● Parallelbetrieb und schrittweise Migration sind
möglich
Fragen?
Danke für die Aufmerksamkeit :-)

More Related Content

What's hot

How to Build SPA with Vue Router 2.0
How to Build SPA with Vue Router 2.0How to Build SPA with Vue Router 2.0
How to Build SPA with Vue Router 2.0Takuya Tejima
 
Introduction to VueJS & Vuex
Introduction to VueJS & VuexIntroduction to VueJS & Vuex
Introduction to VueJS & VuexBernd Alter
 
Heroku pop-behind-the-sense
Heroku pop-behind-the-senseHeroku pop-behind-the-sense
Heroku pop-behind-the-senseBen Lin
 
Building scalable applications with angular js
Building scalable applications with angular jsBuilding scalable applications with angular js
Building scalable applications with angular jsAndrew Alpert
 
AngularJS - The Next Big Thing?
AngularJS - The Next Big Thing?AngularJS - The Next Big Thing?
AngularJS - The Next Big Thing?Tom Hombergs
 
Multi modularized project setup with gulp, typescript and angular.js
Multi modularized project setup with gulp, typescript and angular.jsMulti modularized project setup with gulp, typescript and angular.js
Multi modularized project setup with gulp, typescript and angular.jsDavid Amend
 
Vue 2.0 + Vuex Router & Vuex at Vue.js
Vue 2.0 + Vuex Router & Vuex at Vue.jsVue 2.0 + Vuex Router & Vuex at Vue.js
Vue 2.0 + Vuex Router & Vuex at Vue.jsTakuya Tejima
 
Vue js 大型專案架構
Vue js 大型專案架構Vue js 大型專案架構
Vue js 大型專案架構Hina Chen
 
Angular JS blog tutorial
Angular JS blog tutorialAngular JS blog tutorial
Angular JS blog tutorialClaude Tech
 
Ionic으로 모바일앱 만들기 #4
Ionic으로 모바일앱 만들기 #4Ionic으로 모바일앱 만들기 #4
Ionic으로 모바일앱 만들기 #4성일 한
 
Angularjs - lazy loading techniques
Angularjs - lazy loading techniques Angularjs - lazy loading techniques
Angularjs - lazy loading techniques Nir Kaufman
 
Vue routing tutorial getting started with vue router
Vue routing tutorial getting started with vue routerVue routing tutorial getting started with vue router
Vue routing tutorial getting started with vue routerKaty Slemon
 
AngularJS Basics and Best Practices - CC FE &UX
AngularJS Basics and Best Practices - CC FE &UXAngularJS Basics and Best Practices - CC FE &UX
AngularJS Basics and Best Practices - CC FE &UXJWORKS powered by Ordina
 
Vue.js is boring - and that's a good thing
Vue.js is boring - and that's a good thingVue.js is boring - and that's a good thing
Vue.js is boring - and that's a good thingJoonas Lehtonen
 
Vue.js
Vue.jsVue.js
Vue.jsBADR
 
Backbone.js
Backbone.jsBackbone.js
Backbone.jsVO Tho
 

What's hot (20)

How to Build SPA with Vue Router 2.0
How to Build SPA with Vue Router 2.0How to Build SPA with Vue Router 2.0
How to Build SPA with Vue Router 2.0
 
Vue business first
Vue business firstVue business first
Vue business first
 
AngularJs Crash Course
AngularJs Crash CourseAngularJs Crash Course
AngularJs Crash Course
 
Vuex
VuexVuex
Vuex
 
Introduction to VueJS & Vuex
Introduction to VueJS & VuexIntroduction to VueJS & Vuex
Introduction to VueJS & Vuex
 
Heroku pop-behind-the-sense
Heroku pop-behind-the-senseHeroku pop-behind-the-sense
Heroku pop-behind-the-sense
 
Building scalable applications with angular js
Building scalable applications with angular jsBuilding scalable applications with angular js
Building scalable applications with angular js
 
AngularJS - The Next Big Thing?
AngularJS - The Next Big Thing?AngularJS - The Next Big Thing?
AngularJS - The Next Big Thing?
 
Multi modularized project setup with gulp, typescript and angular.js
Multi modularized project setup with gulp, typescript and angular.jsMulti modularized project setup with gulp, typescript and angular.js
Multi modularized project setup with gulp, typescript and angular.js
 
Vue 2.0 + Vuex Router & Vuex at Vue.js
Vue 2.0 + Vuex Router & Vuex at Vue.jsVue 2.0 + Vuex Router & Vuex at Vue.js
Vue 2.0 + Vuex Router & Vuex at Vue.js
 
Vue js 大型專案架構
Vue js 大型專案架構Vue js 大型專案架構
Vue js 大型專案架構
 
Angular JS blog tutorial
Angular JS blog tutorialAngular JS blog tutorial
Angular JS blog tutorial
 
Ionic으로 모바일앱 만들기 #4
Ionic으로 모바일앱 만들기 #4Ionic으로 모바일앱 만들기 #4
Ionic으로 모바일앱 만들기 #4
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
Angularjs - lazy loading techniques
Angularjs - lazy loading techniques Angularjs - lazy loading techniques
Angularjs - lazy loading techniques
 
Vue routing tutorial getting started with vue router
Vue routing tutorial getting started with vue routerVue routing tutorial getting started with vue router
Vue routing tutorial getting started with vue router
 
AngularJS Basics and Best Practices - CC FE &UX
AngularJS Basics and Best Practices - CC FE &UXAngularJS Basics and Best Practices - CC FE &UX
AngularJS Basics and Best Practices - CC FE &UX
 
Vue.js is boring - and that's a good thing
Vue.js is boring - and that's a good thingVue.js is boring - and that's a good thing
Vue.js is boring - and that's a good thing
 
Vue.js
Vue.jsVue.js
Vue.js
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 

Viewers also liked

Building Enterprise Applications with AngularJS (GDG DevFest Karlsruhe 2014)
Building Enterprise Applications with AngularJS (GDG DevFest Karlsruhe 2014)Building Enterprise Applications with AngularJS (GDG DevFest Karlsruhe 2014)
Building Enterprise Applications with AngularJS (GDG DevFest Karlsruhe 2014)Christian Janz
 
Keeping Things Simple In A Growing AngularJS App.
Keeping Things Simple In A Growing AngularJS App.Keeping Things Simple In A Growing AngularJS App.
Keeping Things Simple In A Growing AngularJS App.Brandon Boswell, MBA
 
AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)Brian Swartzfager
 
AngularJS performance & production tips
AngularJS performance & production tipsAngularJS performance & production tips
AngularJS performance & production tipsNir Kaufman
 
Singapore startup ecosystem and entrepreneur toolbox - Jun 2014
Singapore startup ecosystem and entrepreneur toolbox - Jun 2014Singapore startup ecosystem and entrepreneur toolbox - Jun 2014
Singapore startup ecosystem and entrepreneur toolbox - Jun 2014Arnaud Bonzom
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS ArchitectureEyal Vardi
 
Medienbiographie
MedienbiographieMedienbiographie
MedienbiographiePrzemekR
 
1 .produktpräsenter 25 folien mit dvd
1 .produktpräsenter  25 folien mit dvd1 .produktpräsenter  25 folien mit dvd
1 .produktpräsenter 25 folien mit dvdgwitz
 
Ciclos Grado Medio
Ciclos Grado MedioCiclos Grado Medio
Ciclos Grado Mediogerlose
 
KTM Technologies: Konzeptvergleich eines Fahrzeugheckrahmens hinsichtlich Fes...
KTM Technologies: Konzeptvergleich eines Fahrzeugheckrahmens hinsichtlich Fes...KTM Technologies: Konzeptvergleich eines Fahrzeugheckrahmens hinsichtlich Fes...
KTM Technologies: Konzeptvergleich eines Fahrzeugheckrahmens hinsichtlich Fes...CADFEM Austria GmbH
 
El pelotazo viaja en ave.
El pelotazo viaja en ave.El pelotazo viaja en ave.
El pelotazo viaja en ave.Pere Eurotopia
 
FAMOSAS SIN MAQUILLAJE
FAMOSAS SIN MAQUILLAJEFAMOSAS SIN MAQUILLAJE
FAMOSAS SIN MAQUILLAJEanaccapote
 
Hubble - Parte 4
Hubble - Parte 4Hubble - Parte 4
Hubble - Parte 4MERCIO
 
Trabajo final heli
Trabajo final heliTrabajo final heli
Trabajo final heliHeli Lazaro
 

Viewers also liked (20)

Building Enterprise Applications with AngularJS (GDG DevFest Karlsruhe 2014)
Building Enterprise Applications with AngularJS (GDG DevFest Karlsruhe 2014)Building Enterprise Applications with AngularJS (GDG DevFest Karlsruhe 2014)
Building Enterprise Applications with AngularJS (GDG DevFest Karlsruhe 2014)
 
Keeping Things Simple In A Growing AngularJS App.
Keeping Things Simple In A Growing AngularJS App.Keeping Things Simple In A Growing AngularJS App.
Keeping Things Simple In A Growing AngularJS App.
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
 
AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)
 
AngularJS performance & production tips
AngularJS performance & production tipsAngularJS performance & production tips
AngularJS performance & production tips
 
Singapore startup ecosystem and entrepreneur toolbox - Jun 2014
Singapore startup ecosystem and entrepreneur toolbox - Jun 2014Singapore startup ecosystem and entrepreneur toolbox - Jun 2014
Singapore startup ecosystem and entrepreneur toolbox - Jun 2014
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
 
Medienbiographie
MedienbiographieMedienbiographie
Medienbiographie
 
1 .produktpräsenter 25 folien mit dvd
1 .produktpräsenter  25 folien mit dvd1 .produktpräsenter  25 folien mit dvd
1 .produktpräsenter 25 folien mit dvd
 
Ciclos Grado Medio
Ciclos Grado MedioCiclos Grado Medio
Ciclos Grado Medio
 
KTM Technologies: Konzeptvergleich eines Fahrzeugheckrahmens hinsichtlich Fes...
KTM Technologies: Konzeptvergleich eines Fahrzeugheckrahmens hinsichtlich Fes...KTM Technologies: Konzeptvergleich eines Fahrzeugheckrahmens hinsichtlich Fes...
KTM Technologies: Konzeptvergleich eines Fahrzeugheckrahmens hinsichtlich Fes...
 
El pelotazo viaja en ave.
El pelotazo viaja en ave.El pelotazo viaja en ave.
El pelotazo viaja en ave.
 
Me Asusta
Me AsustaMe Asusta
Me Asusta
 
FAMOSAS SIN MAQUILLAJE
FAMOSAS SIN MAQUILLAJEFAMOSAS SIN MAQUILLAJE
FAMOSAS SIN MAQUILLAJE
 
EPIDEMIOLOGIA
EPIDEMIOLOGIAEPIDEMIOLOGIA
EPIDEMIOLOGIA
 
Hubble - Parte 4
Hubble - Parte 4Hubble - Parte 4
Hubble - Parte 4
 
Trabajo final heli
Trabajo final heliTrabajo final heli
Trabajo final heli
 
Educación Sexual
Educación  SexualEducación  Sexual
Educación Sexual
 
Basar
BasarBasar
Basar
 
Por El Papa
Por El PapaPor El Papa
Por El Papa
 

Similar to Zukunftssichere Anwendungen mit AngularJS 1.x entwickeln (GDG DevFest Karlsruhe 2015)

Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6William Marques
 
Angular1x and Angular 2 for Beginners
Angular1x and Angular 2 for BeginnersAngular1x and Angular 2 for Beginners
Angular1x and Angular 2 for BeginnersOswald Campesato
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'sAntônio Roberto Silva
 
Building an angular application -1 ( API: Golang, Database: Postgres) v1.0
Building an angular application -1 ( API: Golang, Database: Postgres) v1.0Building an angular application -1 ( API: Golang, Database: Postgres) v1.0
Building an angular application -1 ( API: Golang, Database: Postgres) v1.0Frost
 
Building Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJSBuilding Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJSAntonio Peric-Mazar
 
Front end development with Angular JS
Front end development with Angular JSFront end development with Angular JS
Front end development with Angular JSBipin
 
WPF and Prism 4.1 Workshop at BASTA Austria
WPF and Prism 4.1 Workshop at BASTA AustriaWPF and Prism 4.1 Workshop at BASTA Austria
WPF and Prism 4.1 Workshop at BASTA AustriaRainer Stropek
 
Building a dashboard using AngularJS
Building a dashboard using AngularJSBuilding a dashboard using AngularJS
Building a dashboard using AngularJSRajthilakMCA
 
Sharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SFSharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SFPierre-Yves Ricau
 
Modern frontend development with VueJs
Modern frontend development with VueJsModern frontend development with VueJs
Modern frontend development with VueJsTudor Barbu
 
AngularJS Internal
AngularJS InternalAngularJS Internal
AngularJS InternalEyal Vardi
 
Adding custom ui controls to your application (1)
Adding custom ui controls to your application (1)Adding custom ui controls to your application (1)
Adding custom ui controls to your application (1)Oro Inc.
 
Angular 2 for Java Developers
Angular 2 for Java DevelopersAngular 2 for Java Developers
Angular 2 for Java DevelopersYakov Fain
 
Patterns Are Good For Managers
Patterns Are Good For ManagersPatterns Are Good For Managers
Patterns Are Good For ManagersAgileThought
 

Similar to Zukunftssichere Anwendungen mit AngularJS 1.x entwickeln (GDG DevFest Karlsruhe 2015) (20)

Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6Angular 2 Migration - JHipster Meetup 6
Angular 2 Migration - JHipster Meetup 6
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Angular1x and Angular 2 for Beginners
Angular1x and Angular 2 for BeginnersAngular1x and Angular 2 for Beginners
Angular1x and Angular 2 for Beginners
 
using Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API'susing Mithril.js + postgREST to build and consume API's
using Mithril.js + postgREST to build and consume API's
 
Building an angular application -1 ( API: Golang, Database: Postgres) v1.0
Building an angular application -1 ( API: Golang, Database: Postgres) v1.0Building an angular application -1 ( API: Golang, Database: Postgres) v1.0
Building an angular application -1 ( API: Golang, Database: Postgres) v1.0
 
mean stack
mean stackmean stack
mean stack
 
Building Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJSBuilding Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJS
 
Front end development with Angular JS
Front end development with Angular JSFront end development with Angular JS
Front end development with Angular JS
 
WPF and Prism 4.1 Workshop at BASTA Austria
WPF and Prism 4.1 Workshop at BASTA AustriaWPF and Prism 4.1 Workshop at BASTA Austria
WPF and Prism 4.1 Workshop at BASTA Austria
 
Angular Js Basics
Angular Js BasicsAngular Js Basics
Angular Js Basics
 
Angular 2.0 - What to expect
Angular 2.0 - What to expectAngular 2.0 - What to expect
Angular 2.0 - What to expect
 
Building a dashboard using AngularJS
Building a dashboard using AngularJSBuilding a dashboard using AngularJS
Building a dashboard using AngularJS
 
Sharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SFSharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SF
 
Modern frontend development with VueJs
Modern frontend development with VueJsModern frontend development with VueJs
Modern frontend development with VueJs
 
Angular2 + rxjs
Angular2 + rxjsAngular2 + rxjs
Angular2 + rxjs
 
AngularJS Internal
AngularJS InternalAngularJS Internal
AngularJS Internal
 
Adding custom ui controls to your application (1)
Adding custom ui controls to your application (1)Adding custom ui controls to your application (1)
Adding custom ui controls to your application (1)
 
Angular 2 for Java Developers
Angular 2 for Java DevelopersAngular 2 for Java Developers
Angular 2 for Java Developers
 
Angular 2 in-1
Angular 2 in-1 Angular 2 in-1
Angular 2 in-1
 
Patterns Are Good For Managers
Patterns Are Good For ManagersPatterns Are Good For Managers
Patterns Are Good For Managers
 

Recently uploaded

The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsYoss Cohen
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFMichael Gough
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 

Recently uploaded (20)

The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platforms
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDF
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 

Zukunftssichere Anwendungen mit AngularJS 1.x entwickeln (GDG DevFest Karlsruhe 2015)

  • 1. Zukunftssichere Anwendungen mit AngularJS 1.x entwickeln Christian Janz (@c_janz) christian.janz@bridging-it.de
  • 2. Wer steht hier vorne? Christian Janz Consultant bei BridgingIT GmbH in Mannheim Interesse: Architektur und Entwicklung von Geschäftsanwendungen mit modernen Frameworks
  • 3. AngularJS 1.x? Warum nicht Angular 2? “Angular 2 is currently in Developer Preview. We recommend using Angular 1.X for production applications.” https://angular.io/docs/ts/latest/
  • 5. Entwickle die Anwendung mit AngularJS 1.x, aber mit Angular 2 im Blick Lösungsansatz
  • 6. Neuerung in Angular 2 Eine Auswahl :-)
  • 7. Neue Template-Syntax 1. <li *ng-for="#hero of heroes" (click)="onSelect(hero)"> 2. <span class="badge">{{hero.id}}</span> {{hero.name}} 3. </li>
  • 8. ES 2015 Support / TypeScript ● Angular 2 wird in TypeScript entwickelt ● Verwendet ES 2015 Module ○ Framework wird modularer ○ Kein eigenes Modulsystem mehr (angular. module(...)) ● Einsatz von Decorators für Metadaten 1. import {bootstrap, Component} from 'angular2/angular2'; 2. 3. @Component({ 4. selector: 'my-app', 5. template: '<h1>My First Angular 2 App</h1>' 6. }) 7. class AppComponent { } 8. 9. bootstrap(AppComponent);
  • 9. Verbesserte Dependency Injection ● Hierarchische Dependency Injection Container ● Matching der Abhängigkeiten über Typ, nicht über Name
  • 10. Komponentenbasiert ● Keine Standalone Controller mehr (ng-controller=””) ● Kein $scope mehr ● @Component: Komponente (≅ AngularJS 1.x Direktiven) ● @Directive: Komponente ohne View
  • 11. Neuer Router ● Komponentenbasiert ● Deutlich mächtiger als ng-route ● Parallelentwicklung für Angular 2 und Angular 1.x ○ Gleiche API ○ Soll Migration erleichtern
  • 13. TypeScript und EcmaScript ES 5 ES 2015 TypeScript
  • 15. Import, Export http://www.2ality.com/2014/09/es6-modules-final.html // lib/math.js export function sum(x, y) { return x + y; } export const pi = 3.141593; // app.js import * as math from "lib/math"; alert("2π = " + math.sum(math.pi, math.pi)); // otherApp.js import {sum, pi} from "lib/math"; alert("2π = " + sum(pi, pi));
  • 16. Default Export http://www.2ality.com/2014/09/es6-modules-final.html //------ myFunc.js ------ export default function foo() { ... }; //------ main1.js ------ import myFunc from 'myFunc'; // import { default as foo } from 'myFunc'; myFunc();
  • 18. Browser-Support Kein Browser unterstützt bisher nativ ES 2015 Module ⇒ Bibliotheken/Tools notwendig
  • 20. Services angular.module('myTestApp') .factory('gitHubService', function ($http) { function buildRepoUrl(userId) { return 'https://api.github.com/users/' + userId + '/repos'; } function getRepos(userId) { return $http.get(buildRepoUrl(userId)) .then(function (result) { return result.data; }); } return { getRepos: getRepos } }); export default class GitHubService { constructor(private $http: angular.IHttpService) { } private buildRepoUrl(userId: string): string { return `https://api.github.com/users/${userId} /repos`; } public getRepos(userId: string): any { return this.$http.get(this.buildRepoUrl(userId)) .then(function (result) { return result.data; }); } }
  • 21. Bootstrapping //app.js angular.module('myTestApp', []); ------------ //index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Old Code</title> </head> <body ng-app="myTestApp"> <script src="bower_components/angular/angular.js" ></script> <script src="app.js"></script> <script src="github.service.js"></script> </body> </html> //app.ts import angular = require('angular'); import GitHubService from './github.service'; let module = angular.module('myTestApp', []) .service('gitHubService', GitHubService); angular.bootstrap(window.document.body, [module.name]); ------------ //index.html <!DOCTYPE html> <html lang="en"> <head>...</head> <body> <script src="jspm_packages/system.js"></script> <script src="config.js"></script> <script> System.import('lib/app'); </script> </body> </html>
  • 23. ng-controller durch Komponente ersetzen Teil 1: Controller Aliasing //index.html <body ng-app="myTestApp"> <main ng-controller="MainCtrl"> <ul ng-controller="RepoListCtrl"> <li ng-repeat="repo in repos" ng-click="selectRepo(repo)"> {{repo}} </li> </ul> <div> Selected Repo: {{selectedRepo}} </div> </main> </body> //index.html <body ng-app="myTestApp"> <main ng-controller="MainCtrl as mainCtrl"> <ul ng-controller="RepoListCtrl as repoListCtrl"> <li ng-repeat="repo in repoListCtrl.repos" ng-click="mainCtrl.selectRepo(repo)"> {{repo}} </li> </ul> <div> Selected Repo: {{mainCtrl.selectedRepo}} </div> </main> </body>
  • 24. //index.html <body ng-app="myTestApp"> <main ng-controller="MainCtrl as mainCtrl"> <ul ng-controller="RepoListCtrl as repoListCtrl"> <li ng-repeat="repo in repoListCtrl.repos" ng-click="mainCtrl.selectRepo(repo)"> {{repo}} </li> </ul> <div> Selected Repo: {{mainCtrl.selectedRepo}} </div> </main> </body> ng-controller durch Komponente ersetzen Teil 2: Direktive erstellen //index.html <body ng-app="myTestApp"> <main-app></main-app> </body> //main.directive.js angular.module('myTestApp') .directive('mainApp', function() { return { scope: true, templateUrl: 'mainApp.template.html' } }) //mainApp.template.html <main ng-controller="MainCtrl as mainCtrl"> <ul ng-controller="RepoListCtrl as repoListCtrl"> <li ng-repeat="repo in repoListCtrl.repos" ng-click="mainCtrl.selectRepo(repo)"> {{repo}} </li> </ul> <div> Selected Repo: {{mainCtrl.selectedRepo}} </div> </main>
  • 25. ng-controller durch Komponente ersetzen Teil 3: Root ng-controller entfernen //index.html <body ng-app="myTestApp"> <main-app></main-app> </body> //main.directive.js angular.module('myTestApp') .directive('mainApp', function() { return { scope: true, templateUrl: 'mainApp.template.html' } }) //mainApp.template.html <main ng-controller="MainCtrl as mainCtrl"> <ul ng-controller="RepoListCtrl as repoListCtrl"> <li ng-repeat="repo in repoListCtrl.repos" ng-click="mainCtrl.selectRepo(repo)"> {{repo}} </li> </ul> <div> Selected Repo: {{mainCtrl.selectedRepo}} </div> </main> //index.html <body ng-app="myTestApp"> <main-app></main-app> </body> //main.directive.js angular.module('myTestApp') .directive('mainApp', function() { return { scope: true, controller: 'MainCtrl', controllerAs: 'mainCtrl', templateUrl: 'mainApp.template.html' } }) //mainApp.template.html <main> <ul ng-controller="RepoListCtrl as repoListCtrl"> <li ng-repeat="repo in repoListCtrl.repos" ng-click="mainCtrl.selectRepo(repo)"> {{repo}} </li> </ul> <div> Selected Repo: {{mainCtrl.selectedRepo}} </div> </main>
  • 26. ng-controller durch Komponente ersetzen Teil 4: Direktive und Controller kombinieren //main.directive.js angular.module('myTestApp') .directive('mainApp', function() { return { scope: true, controller: 'MainCtrl', controllerAs: 'mainCtrl', templateUrl: 'mainApp.template.html' } }) //main.ctrl.js angular.module('myTestApp') .controller('MainCtrl', function () { this.userId = 'bridgingIT'; this.selectedRepo = ''; this.selectRepo = function(repo) { this.selectedRepo = repo; } }); //main.directive.js angular.module('myTestApp') .directive('mainApp', function() { function MainCtrl() { this.userId = 'bridgingIT'; this.selectedRepo = ''; this.selectRepo = function(repo) { this.selectedRepo = repo; } } return { scope: true, controller: MainCtrl, controllerAs: 'mainCtrl', templateUrl: 'mainApp.template.html' } });
  • 27. ng-controller durch Komponente ersetzen Teil 4b: Direktive in TypeScript //main.directive.js angular.module('myTestApp') .directive('mainApp', function() { function MainCtrl() { this.userId = 'bridgingIT'; this.selectedRepo = ''; this.selectRepo = function(repo) { this.selectedRepo = repo; } } return { scope: true, controller: MainCtrl, controllerAs: 'mainCtrl', templateUrl: 'mainApp.template.html' } }); //main.directive.ts class MainController { public userId: string = 'bridgingIT'; public selectedRepo: string = ''; public onSelectRepo(repo: string) { this.selectedRepo = repo; } } export default () => { return { scope: {}, controller: MainController, controllerAs: 'mainCtrl', templateUrl: 'mainApp.template.html', bindToController: true, } } //app.ts import angular = require('angular'); import MainComponent from './main.directive; let module = angular.module('myTestApp', []) .directive('mainApp', MainComponent) angular.bootstrap(window.document.body, [module.name]);
  • 28. ng-controller durch Komponente ersetzen Teil 5: Teilkomponente extrahieren //mainApp.template.html <main> <ul ng-controller="RepoListCtrl as repoListCtrl"> <li ng-repeat="repo in repoListCtrl.repos" ng-click="mainCtrl.selectRepo(repo)"> {{repo}} </li> </ul> <div> Selected Repo: {{mainCtrl.selectedRepo}} </div> </main> //mainApp.template.html <main> <repo-list></repo-list> <div> Selected Repo: {{mainCtrl.selectedRepo}} </div> </main> // repoList.directive.js angular.module('myTestApp') .directive('repoList', function () { function RepoListCtrl($scope, gitHubService) { var that = this; $scope.$watch('mainCtrl.userId', function (newUserId) { gitHubService.getRepos(newUserId) .then(function (result) { that.repos = result.map(function (repo) { return repo.name; }); }); }); } return { scope: true, controller: RepoListCtrl, controllerAs: 'repoListCtrl', templateUrl: 'repoList.template.html' } });
  • 29. ng-controller durch Komponente ersetzen Teil 5: Input und Output Parameter // repoList.directive.js angular.module('myTestApp') .directive('repoList', function () { function RepoListCtrl($scope, gitHubService) { var that = this; $scope.$watch('mainCtrl.userId', function (newUserId) { gitHubService.getRepos(newUserId) .then(function (result) { that.repos = result.map(function (repo) { return repo.name; }); }); }); } return { scope: true, controller: RepoListCtrl, controllerAs: 'repoListCtrl', templateUrl: 'repoList.template.html' } }); // repoList.template.html <ul> <li ng-repeat="repo in repoListCtrl.repos" ng-click="mainCtrl.selectRepo(repo)"> {{repo}} </li> </ul> //mainApp.template.html <main> <repo-list></repo-list> <div> Selected Repo: {{mainCtrl.selectedRepo}} </div> </main>
  • 30. ng-controller durch Komponente ersetzen Teil 5: Input und Output Parameter // repoList.directive.js angular.module('myTestApp') .directive('repoList', function () { function RepoListCtrl($scope, gitHubService) { var that = this; $scope.$watch('repoListCtrl.userId', function (newUserId) { gitHubService.getRepos(newUserId) .then(function (result) { that.repos = result.map(function (repo) { return repo.name; }); }); }); this.selectRepo = function(repo) { that.onSelectRepo({repo: repo}); } } return { scope: { userId: '=', onSelectRepo: '&' }, bindToController: true, controller: RepoListCtrl, controllerAs: 'repoListCtrl', templateUrl: 'repoList.template.html' } }); // repoList.template.html <ul> <li ng-repeat="repo in repoListCtrl.repos" ng-click="repoListCtrl.selectRepo(repo)"> {{repo}} </li> </ul> //mainApp.template.html <main> <repo-list user-id="mainCtrl.userId" on-select-repo="mainCtrl.selectRepo(repo)"> </repo-list> <div> Selected Repo: {{mainCtrl.selectedRepo}} </div> </main>
  • 33. AngularJS 1.x und Angular 2 in einer Anwendung https://github.com/angular/ngUpgrade
  • 34. Fazit
  • 35. AngularJS 1.x ist nicht tot ● Einige Ansätze aus Angular 2 können auch in AngularJS 1.x genutzt werden ○ ES 2015 Module ○ Komponenten ● TypeScript erleichtert Refactoring ● Parallelbetrieb und schrittweise Migration sind möglich
  • 37. Danke für die Aufmerksamkeit :-)