SlideShare una empresa de Scribd logo
1 de 37
Descargar para leer sin conexión
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 :-)

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Destacado

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
 

Destacado (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 a 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 a 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
 

Último

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 

Último (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

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 :-)