diff --git a/app/contact-detail-component/contact-detail-component.es5.js b/app/contact-detail-component/contact-detail-component.es5.js index 2d183ee..482f95a 100644 --- a/app/contact-detail-component/contact-detail-component.es5.js +++ b/app/contact-detail-component/contact-detail-component.es5.js @@ -2,21 +2,11 @@ angular .module('contact-detail-component', ['ngRoute', 'contacts-service', 'zippy-component']) .config(function ($routeProvider) { $routeProvider.when('/contact/:id', { + controller: function (contactsService, $routeParams) { + this.contact = contactsService.getContact($routeParams.id); + }, + controllerAs: '$ctrl', template: '' }); }) - .component('contactDetailComponent', { - templateUrl: 'app/contact-detail-component/contact-detail-component.html', - controller: function (contactsService, $routeParams) { - - this.$onInit = function () { - this.contact = contactsService.getContact($routeParams.id); - this.toggleCaption(false); - }; - - this.toggleCaption = function (closed) { - this.zippyCaption = closed ? 'Show address' : 'Hide address'; - }; - } -}); diff --git a/app/contact-detail-component/contact-detail-component.html b/app/contact-detail-component/contact-detail-component.html index 4f1f08b..e18abf9 100644 --- a/app/contact-detail-component/contact-detail-component.html +++ b/app/contact-detail-component/contact-detail-component.html @@ -2,52 +2,53 @@
- - {{$ctrl.contact.name}} + + {{contact?.name}}
email Email: - {{$ctrl.contact.email || '-'}} + {{contact?.email || '-'}}
phone Phone: - {{$ctrl.contact.phone || '-'}} + {{contact?.phone || '-'}}
cake Birthday: - {{$ctrl.contact.birthday || '-'}} + {{contact?.birthday || '-'}}
public Website: - {{$ctrl.contact.website || '-'}} + {{contact?.website || '-'}}
- + +
location_city Address
Street: - {{$ctrl.contact.address.street || '-'}} + {{contact?.address?.street || '-'}}
Zipcode: - {{$ctrl.contact.address.zip || '-'}} + {{contact?.address?.zip || '-'}}
City: - {{$ctrl.contact.address.city || '-'}} + {{contact?.address?.city || '-'}}
Country: - {{$ctrl.contact.address.country || '-'}} + {{contact?.address?.country || '-'}}
- + \ No newline at end of file diff --git a/app/contact-detail-component/contact-detail-component.ts b/app/contact-detail-component/contact-detail-component.ts new file mode 100644 index 0000000..b9420a2 --- /dev/null +++ b/app/contact-detail-component/contact-detail-component.ts @@ -0,0 +1,27 @@ +import {Component, Input,Inject} from '@angular/core'; +import {Contact} from '../models/contact'; +import {ContactsService} from '../contacts-service/contacts-service' +import {upgradeAdapter} from '../upgrade-adapter'; +// upgradeAdapter.upgradeNg1Provider('contactsService'); + + upgradeAdapter.upgradeNg1Provider('$routeParams'); +const ZippyComponent = upgradeAdapter.upgradeNg1Component('zippyComponent'); +@Component({ + selector: 'contact-detail-component', + templateUrl: 'app/contact-detail-component/contact-detail-component.html', + directives: [ZippyComponent], + providers: [ContactsService] +}) +export class ContactDetailComponent { + @Input() contact: Contact; + zippyCaption: string; + + constructor (@Inject('$routeParams') $routeParams: any, + contactsService: ContactsService) { + this.contact = contactsService.getContact($routeParams.id); + this.toggleCaption(false); +} + toggleCaption (closed: boolean) { + this.zippyCaption = closed ? 'Show address' : 'Hide address'; + } +} \ No newline at end of file diff --git a/app/contacts-list-component/contacts-list-component.es5.js b/app/contacts-list-component/contacts-list-component.es5.js index 624388f..ea61978 100644 --- a/app/contacts-list-component/contacts-list-component.es5.js +++ b/app/contacts-list-component/contacts-list-component.es5.js @@ -1,5 +1,5 @@ angular - .module('contacts-list-component', ['ngRoute', 'contacts-service']) + .module('contacts-list-component', ['ngRoute', 'contacts-service','contacts-list-item-component']) .config(function ($routeProvider) { $routeProvider.when('/', { template: '' diff --git a/app/contacts-list-component/contacts-list-component.html b/app/contacts-list-component/contacts-list-component.html index a95d466..66a9bdd 100644 --- a/app/contacts-list-component/contacts-list-component.html +++ b/app/contacts-list-component/contacts-list-component.html @@ -1,8 +1,5 @@ + \ No newline at end of file diff --git a/app/contacts-list-item-component/contacts-list-item-component.html b/app/contacts-list-item-component/contacts-list-item-component.html new file mode 100644 index 0000000..7cedd21 --- /dev/null +++ b/app/contacts-list-item-component/contacts-list-item-component.html @@ -0,0 +1,4 @@ + + + {{contact.name}} + \ No newline at end of file diff --git a/app/contacts-list-item-component/contacts-list-item-component.ts b/app/contacts-list-item-component/contacts-list-item-component.ts new file mode 100644 index 0000000..575fefc --- /dev/null +++ b/app/contacts-list-item-component/contacts-list-item-component.ts @@ -0,0 +1,10 @@ +import {Component, Input} from '@angular/core'; +import {Contact} from '../models/contact'; + +@Component({ + selector: 'contacts-list-item-component', + templateUrl: 'app/contacts-list-item-component/contacts-list-item-component.html' +}) +export class ContactsListItemComponent { + @Input() contact: Contact; +} \ No newline at end of file diff --git a/app/contacts-service/contacts-service.es5.js b/app/contacts-service/contacts-service.es5.js deleted file mode 100644 index 16bb51b..0000000 --- a/app/contacts-service/contacts-service.es5.js +++ /dev/null @@ -1,183 +0,0 @@ -angular - .module('contacts-service', []) - .service('contactsService', function ContactsService () { - - var CONTACT_DATA = [ - { - id: 0, - name: 'Christoph Burgdorf', - email: 'christoph@thoughtram.io', - phone: '+49 000 1111', - birthday: '1984-01-02', - website: 'thoughtram.io', - image: '/assets/images/0.jpg', - address: { - street: 'thoughtram road 1', - zip: '65222', - city: 'Hanover', - country: 'Germany' - } - }, - { - id: 1, - name: 'Pascal Precht', - email: 'pascal@thoughtram.io', - phone: '+49 000 222', - birthday: '1991-03-31', - website: 'thoughtram.io', - image: '/assets/images/1.jpg', - address: { - street: 'thoughtram road 1', - zip: '65222', - city: 'Hanover', - country: 'Germany' - } - }, - { - id: 2, - name: 'Nicole Hansen', - email: 'who@car.es', - phone: '+49 000 333', - birthday: '1981-03-31', - website: '', - image: '/assets/images/3.jpg', - address: { - street: 'Who Cares Street 42', - zip: '65222', - city: 'Sun Funcisco', - country: 'United States' - } - }, - { - id: 3, - name: 'Zoe Moore', - email: 'zoe@moore.com', - phone: '+49 000 000', - birthday: '1990-02-18', - website: '', - image: '/assets/images/4.jpg', - address: { - street: '3745 denny street', - zip: '86337', - city: 'Ballinasloe', - country: 'United States' - } - }, - { - id: 4, - name: 'Diane Hale', - email: '', - phone: '', - birthday: '', - website: '', - image: '/assets/images/5.jpg', - address: { - street: '1459 tara street', - zip: '18371', - city: 'Bray', - country: 'United States' - } - }, - { - id: 5, - name: 'Diana Ellis', - email: '', - phone: '', - birthday: '', - website: '', - image: '/assets/images/6.jpg', - address: { - street: '6503 tara street', - zip: '43378', - city: 'Dungarvan', - country: 'United States' - } - }, - { - id: 6, - name: 'Barry Ford', - email: '', - phone: '', - birthday: '', - website: '', - image: '/assets/images/7.jpg', - address: { - street: '6554 park lane', - zip: '43378', - city: 'Rush', - country: 'United States' - } - }, - { - id: 7, - name: 'Ella Grant', - email: '', - phone: '', - birthday: '', - website: '', - image: '/assets/images/8.jpg', - address: { - street: '2749 church road', - zip: '87125', - city: 'Clonakilty', - country: 'United States' - } - }, - { - id: 8, - name: 'Brent Mason', - email: '', - phone: '', - birthday: '', - website: '', - image: '/assets/images/9.jpg', - address: { - street: '8436 tara street', - zip: '59949', - city: 'Dundalk', - country: 'United States' - } - }, - { - id: 9, - name: 'Sam Thomas', - email: '', - phone: '', - birthday: '', - website: '', - image: '/assets/images/10.jpg', - address: { - street: '2523 park road', - zip: '59949', - city: 'Drogheda', - country: 'United States' - } - }, - { - id: 10, - name: 'Vicky Roberts', - email: '', - phone: '', - birthday: '', - website: '', - image: '/assets/images/11.jpg', - address: { - street: '9791 grafton street', - zip: '30165', - city: 'Galway', - country: 'London' - } - } - ]; - - this.getContacts = function () { - return CONTACT_DATA; - }; - - this.getContact = function (id) { - return this.getContacts() - .find(function (contact) { - return contact.id == id; - }) - } - }); diff --git a/app/contacts-service/contacts-service.ts b/app/contacts-service/contacts-service.ts new file mode 100644 index 0000000..ec999e0 --- /dev/null +++ b/app/contacts-service/contacts-service.ts @@ -0,0 +1,180 @@ +import {Injectable} from '@angular/core'; + +@Injectable() +export class ContactsService { + private CONTACT_DATA = [ + { + id: 0, + name: 'Christoph Burgdorf', + email: 'christoph@thoughtram.io', + phone: '+49 000 1111', + birthday: '1984-01-02', + website: 'thoughtram.io', + image: '/assets/images/0.jpg', + address: { + street: 'thoughtram road 1', + zip: '65222', + city: 'Hanover', + country: 'Germany' + } + }, + { + id: 1, + name: 'Pascal Precht', + email: 'pascal@thoughtram.io', + phone: '+49 000 222', + birthday: '1991-03-31', + website: 'thoughtram.io', + image: '/assets/images/1.jpg', + address: { + street: 'thoughtram road 1', + zip: '65222', + city: 'Hanover', + country: 'Germany' + } + }, + { + id: 2, + name: 'Nicole Hansen', + email: 'who@car.es', + phone: '+49 000 333', + birthday: '1981-03-31', + website: '', + image: '/assets/images/3.jpg', + address: { + street: 'Who Cares Street 42', + zip: '65222', + city: 'Sun Funcisco', + country: 'United States' + } + }, + { + id: 3, + name: 'Zoe Moore', + email: 'zoe@moore.com', + phone: '+49 000 000', + birthday: '1990-02-18', + website: '', + image: '/assets/images/4.jpg', + address: { + street: '3745 denny street', + zip: '86337', + city: 'Ballinasloe', + country: 'United States' + } + }, + { + id: 4, + name: 'Diane Hale', + email: '', + phone: '', + birthday: '', + website: '', + image: '/assets/images/5.jpg', + address: { + street: '1459 tara street', + zip: '18371', + city: 'Bray', + country: 'United States' + } + }, + { + id: 5, + name: 'Diana Ellis', + email: '', + phone: '', + birthday: '', + website: '', + image: '/assets/images/6.jpg', + address: { + street: '6503 tara street', + zip: '43378', + city: 'Dungarvan', + country: 'United States' + } + }, + { + id: 6, + name: 'Barry Ford', + email: '', + phone: '', + birthday: '', + website: '', + image: '/assets/images/7.jpg', + address: { + street: '6554 park lane', + zip: '43378', + city: 'Rush', + country: 'United States' + } + }, + { + id: 7, + name: 'Ella Grant', + email: '', + phone: '', + birthday: '', + website: '', + image: '/assets/images/8.jpg', + address: { + street: '2749 church road', + zip: '87125', + city: 'Clonakilty', + country: 'United States' + } + }, + { + id: 8, + name: 'Brent Mason', + email: '', + phone: '', + birthday: '', + website: '', + image: '/assets/images/9.jpg', + address: { + street: '8436 tara street', + zip: '59949', + city: 'Dundalk', + country: 'United States' + } + }, + { + id: 9, + name: 'Sam Thomas', + email: '', + phone: '', + birthday: '', + website: '', + image: '/assets/images/10.jpg', + address: { + street: '2523 park road', + zip: '59949', + city: 'Drogheda', + country: 'United States' + } + }, + { + id: 10, + name: 'Vicky Roberts', + email: '', + phone: '', + birthday: '', + website: '', + image: '/assets/images/11.jpg', + address: { + street: '9791 grafton street', + zip: '30165', + city: 'Galway', + country: 'London' + } + } + ]; + + getContacts () { + return this.CONTACT_DATA; + } + + getContact (id: string) { + return this.CONTACT_DATA.find(contact => contact.id.toString() === id); + } +} diff --git a/app/downgrades.ts b/app/downgrades.ts new file mode 100644 index 0000000..5644431 --- /dev/null +++ b/app/downgrades.ts @@ -0,0 +1,14 @@ +import {upgradeAdapter} from './upgrade-adapter'; +import {ContactsListItemComponent} from './contacts-list-item-component/contacts-list-item-component'; +import {ContactDetailComponent} from './contact-detail-component/contact-detail-component'; +import {ContactsService} from './contacts-service/contacts-service' + +declare let angular: any; +upgradeAdapter.addProvider(ContactsListItemComponent); + +angular.module('contacts-list-item-component', []) + .directive('contactsListItemComponent', upgradeAdapter.downgradeNg2Component(ContactsListItemComponent)); +angular.module('contact-detail-component') + .directive('contactDetailComponent', upgradeAdapter.downgradeNg2Component(ContactDetailComponent)); +angular.module('contacts-service', []) + .service('contactsService', upgradeAdapter.downgradeNg2Provider(ContactsService)); \ No newline at end of file diff --git a/app/main.ts b/app/main.ts new file mode 100644 index 0000000..f1f9bfb --- /dev/null +++ b/app/main.ts @@ -0,0 +1,7 @@ +import {upgradeAdapter} from './upgrade-adapter'; +import './downgrades'; +import {ContactsService} from './contacts-service/contacts-service' + +upgradeAdapter.bootstrap(document.body, ['contacts-app']); +upgradeAdapter.addProvider(ContactsService); + diff --git a/app/models/contact.ts b/app/models/contact.ts new file mode 100644 index 0000000..8f3d905 --- /dev/null +++ b/app/models/contact.ts @@ -0,0 +1,17 @@ +interface Address { + street: string; + city: string; + zip: string; + country: string; +} + +export interface Contact { + id: number; + name: string; + email: string; + phone: string; + birthday: string; + website: string; + image: string; + address: Address; +} \ No newline at end of file diff --git a/app/upgrade-adapter.ts b/app/upgrade-adapter.ts new file mode 100644 index 0000000..c0af4e9 --- /dev/null +++ b/app/upgrade-adapter.ts @@ -0,0 +1,3 @@ +import { UpgradeAdapter } from '@angular/upgrade'; + +export const upgradeAdapter = new UpgradeAdapter(); \ No newline at end of file diff --git a/index.html b/index.html index e48ff1b..a065554 100644 --- a/index.html +++ b/index.html @@ -1,8 +1,8 @@ - + - Angular Migration App by thoughtram + Angular Migration App @@ -16,17 +16,67 @@ - - - - - - - - - - - + + + + + + + + + + + + + + + + + diff --git a/npm-debug.log.1644013654 b/npm-debug.log.1644013654 new file mode 100644 index 0000000..e69de29