Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 4c705a7

Browse files
committed
Updated the button components to work with the new upgrade adapter
Anything using the old upgradeAdapter doesn't seem to work anymore. Instead we create a directive that extends UpgradeComponent. This does the upgrade for us. Converted the ng2 buttons bootstrapper to an actual ng2 component. Otherwise we'd have to figure out how to downgrade the angular 2 components, which I wasn't ready to tackle yet.
1 parent 5ffae07 commit 4c705a7

File tree

5 files changed

+60
-35
lines changed

5 files changed

+60
-35
lines changed

bootstrapper/app.routing.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { WelcomeComponent } from './welcome.component'
55
import { InputsRootComponent } from './inputs/inputRoot';
66
import { InputsNg1BootstrapperComponent } from './inputs/inputBootstrapper';
77
import { InputsBootstrapper } from './inputs/inputsNg2Bootstrapper';
8-
import { ButtonsNg1BootstrapperComponent, ButtonsNg2BootstrapperComponent } from './buttons/buttonBootstrapper';
8+
import { ButtonsNg1BootstrapperComponent } from './buttons/buttonBootstrapper';
9+
import { ButtonsNg2BootstrapperComponent } from './buttons/buttonsNg2Bootstrapper';
910
import { ButtonsRootComponent } from './buttons/buttonRoot';
1011
import { PopupRootComponent } from './popup/popupRoot';
1112
import { PopupNg1BootstrapperComponent } from './popup/popupBootstrapper';

bootstrapper/app.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import { WelcomeComponent } from './welcome.component';
2626
import { InputsRootComponent } from './inputs/inputRoot';
2727
import { InputsNg1BootstrapperComponent } from './inputs/inputBootstrapper';
2828
import { InputsBootstrapper } from './inputs/inputsNg2Bootstrapper';
29-
import { ButtonsNg1BootstrapperComponent, ButtonsNg2BootstrapperComponent } from './buttons/buttonBootstrapper';
29+
import { ButtonsNg1BootstrapperComponent, ButtonsNg1Directive } from './buttons/buttonBootstrapper';
30+
import { ButtonsNg2BootstrapperComponent } from './buttons/buttonsNg2Bootstrapper';
3031
import { ButtonsRootComponent } from './buttons/buttonRoot';
3132
import { PopupRootComponent } from './popup/popupRoot';
3233
import { PopupNg1BootstrapperComponent } from './popup/popupBootstrapper';
@@ -92,8 +93,7 @@ angular.module(moduleName, [
9293
ButtonsRootComponent,
9394
ButtonsNg1BootstrapperComponent,
9495
ButtonsNg2BootstrapperComponent,
95-
upgradeAdapter.upgradeNg1Component('tsButtonsNg1'),
96-
upgradeAdapter.upgradeNg1Component('tsButtonsNg2'),
96+
ButtonsNg1Directive,
9797

9898
PopupRootComponent,
9999
PopupNg1BootstrapperComponent,
@@ -133,6 +133,11 @@ angular.module(moduleName, [
133133
],
134134
bootstrap: [App],
135135
providers: [
136+
{
137+
provide: '$scope',
138+
useFactory: injector => injector.get('$rootScope'),
139+
deps: ['$injector']
140+
}
136141
// {
137142
// provide: ApplicationRef,
138143
// useValue: {

bootstrapper/buttons/buttonBootstrapper.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Component } from '@angular/core';
1+
import { Component, Directive, ElementRef, Injector } from '@angular/core';
2+
import { UpgradeComponent } from '@angular/upgrade/static';
23
import * as angular from 'angular';
34

45
export const moduleName: string = 'ButtonTestModule';
@@ -21,26 +22,24 @@ class ButtonTestController {
2122
}
2223

2324
@Component({
24-
selector: 'tsButtonsNg1',
25-
template: '<ts-buttons-ng1></ts-buttons-ng1>'
25+
selector: 'tsButtonsNg1Bootstrapper',
26+
template: '<tsButtonsNg1></tsButtonsNg1>'
2627
})
2728
export class ButtonsNg1BootstrapperComponent { }
2829

29-
@Component({
30-
selector: 'tsButtonsNg2',
31-
template: '<ts-buttons-ng2></ts-buttons-ng2>'
30+
@Directive({
31+
selector: 'tsButtonsNg1'
3232
})
33-
export class ButtonsNg2BootstrapperComponent {}
33+
export class ButtonsNg1Directive extends UpgradeComponent {
34+
constructor(elementRef: ElementRef, injector: Injector) {
35+
super('tsButtonsNg1', elementRef, injector);
36+
}
37+
}
3438

3539
angular.module(moduleName, [])
3640
.component('tsButtonsNg1', {
3741
template: require('./buttonsNg1.html'),
3842
controller: 'ButtonTestController',
3943
controllerAs: 'button',
4044
})
41-
.component('tsButtonsNg2', {
42-
template: require('./buttonsNg2.html'),
43-
controller: 'ButtonTestController',
44-
controllerAs: 'button',
45-
})
4645
.controller('ButtonTestController', ButtonTestController);

bootstrapper/buttons/buttonsNg2.html

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,37 @@ <h3><a href="https://github.com/SamGraber/TypeScript-Angular-Components/tree/mas
22
<div>
33
<h4><a href="https://github.com/SamGraber/TypeScript-Angular-Components/tree/master/source/components/button/button.md">rlButton</a>:</h4>
44
</div>
5-
<div><rl-button-ng (trigger)="button.action('Simple button')">Simple button</rl-button-ng></div>
6-
<div><rl-button-ng type="primary flat" size="lg" (trigger)="button.action('Large primary button')">Large primary button</rl-button-ng></div>
7-
<div><rl-button-ng disabled="true" (trigger)="button.action('Disabled button')">Disabled button</rl-button-ng></div>
5+
<div><rlButton (trigger)="action('Simple button')">Simple button</rlButton></div>
6+
<div><rlButton type="primary flat" size="lg" (trigger)="action('Large primary button')">Large primary button</rlButton></div>
7+
<div><rlButton [disabled]="true" (trigger)="action('Disabled button')">Disabled button</rlButton></div>
88
<div>
99
<h4><a href="https://github.com/SamGraber/TypeScript-Angular-Components/tree/master/source/components/buttonAsync/buttonAsync.md">rlButtonAsync</a>:</h4>
1010
</div>
11-
<div><rl-button-async-ng [action]="button.waitCallback">Async button</rl-button-async-ng></div>
12-
<div><rl-button-async-ng right-aligned="true" [action]="button.waitCallback">Right aligned async button</rl-button-async-ng></div>
13-
<div><rl-button-async-ng type="primary flat" size="lg" [action]="button.waitCallback">Large primary async button</rl-button-async-ng></div>
14-
<div><rl-button-async-ng disabled="true" [action]="button.waitCallback">Disabled async button</rl-button-async-ng></div>
11+
<div><rlButtonAsync [action]="waitCallback">Async button</rlButtonAsync></div>
12+
<!--<div><rlButtonAsync [action]="waitCallback">Right aligned async button</rlButtonAsync></div>-->
13+
<div><rlButtonAsync type="primary flat" size="lg" [action]="waitCallback">Large primary async button</rlButtonAsync></div>
14+
<div><rlButtonAsync [disabled]="true" [action]="waitCallback">Disabled async button</rlButtonAsync></div>
1515
<div>
1616
<h4><a href="https://github.com/SamGraber/TypeScript-Angular-Components/tree/master/source/components/buttonLink/buttonLink.md">rlButtonLink</a>:</h4>
1717
</div>
18-
<div><rl-button-link-ng link="http://google.com">Link button</rl-button-link-ng></div>
19-
<div><rl-button-link-ng type="primary flat" size="lg" link="http://google.com">Large primary link button</rl-button-link-ng></div>
20-
<div><rl-button-link-ng disabled="true" link="http://google.com">Disabled link button</rl-button-link-ng></div>
18+
<div><rlButtonLink link="http://google.com">Link button</rlButtonLink></div>
19+
<div><rlButtonLink type="primary flat" size="lg" link="http://google.com">Large primary link button</rlButtonLink></div>
20+
<div><rlButtonLink [disabled]="true" link="http://google.com">Disabled link button</rlButtonLink></div>
2121
<div>
2222
<h4>rlButtonRoute:</h4>
2323
</div>
24-
<div><rl-button-route-ng link="/misc/ng2">Route link button</rl-button-route-ng></div>
25-
<div><rl-button-route-ng link="/buttons/ng2" active-class="btn-danger">Active route link button</rl-button-route-ng></div>
24+
<div><rlButtonRoute link="/misc/ng2">Route link button</rlButtonRoute></div>
25+
<div><rlButtonRoute link="/buttons/ng2" activeClass="btn-danger">Active route link button</rlButtonRoute></div>
2626
<div>
2727
<h4><a href="https://github.com/SamGraber/TypeScript-Angular-Components/tree/master/source/components/buttonLongClick/buttonLongClick.md">rlButtonLongClick</a>:</h4>
2828
</div>
29-
<div><rl-button-long-click-ng [action]="button.waitCallback">Long click button</rl-button-long-click-ng></div>
30-
<div><rl-button-long-click-ng right-aligned="true" [action]="button.waitCallback">Right aligned long click button</rl-button-long-click-ng></div>
31-
<div><rl-button-long-click-ng type="primary flat" size="lg" [action]="button.waitCallback">Large primary long click button</rl-button-long-click-ng></div>
32-
<div><rl-button-long-click-ng disabled="true" [action]="button.waitCallback">Disabled long click button</rl-button-long-click-ng></div>
29+
<div><rlButtonLongClick [action]="waitCallback">Long click button</rlButtonLongClick></div>
30+
<!--<div><rlButtonLongClick [action]="waitCallback">Right aligned long click button</rlButtonLongClick></div>-->
31+
<div><rlButtonLongClick type="primary flat" size="lg" [action]="waitCallback">Large primary long click button</rlButtonLongClick></div>
32+
<div><rlButtonLongClick [disabled]="true" [action]="waitCallback">Disabled long click button</rlButtonLongClick></div>
3333
<div>
3434
<h4><a href="https://github.com/SamGraber/TypeScript-Angular-Components/tree/master/source/components/buttonToggle/buttonToggle.md">rlButtonToggle</a>:</h4>
3535
</div>
36-
<div><rl-button-toggle-ng (change)="button.action('Toggle button: ' + $event)">Toggle button</rl-button-toggle-ng></div>
37-
<div><rl-button-toggle-ng type="primary flat" size="lg" (change)="button.action('Large toggle button: ' + $event)">Large primary toggle button</rl-button-toggle-ng></div>
38-
<div><rl-button-toggle-ng disabled="true" (change)="button.action('Disabled toggle button: ' + $event)">Disabled toggle button</rl-button-toggle-ng></div>
36+
<div><rlButtonToggle (valueChange)="action('Toggle button: ' + $event)">Toggle button</rlButtonToggle></div>
37+
<div><rlButtonToggle type="primary flat" size="lg" (valueChange)="action('Large toggle button: ' + $event)">Large primary toggle button</rlButtonToggle></div>
38+
<div><rlButtonToggle [disabled]="true" (valueChange)="action('Disabled toggle button: ' + $event)">Disabled toggle button</rlButtonToggle></div>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Component } from '@angular/core';
2+
import { Observable } from 'rxjs';
3+
4+
@Component({
5+
selector: 'tsButtonsBootstrapper',
6+
template: require('./buttonsNg2.html'),
7+
})
8+
export class ButtonsNg2BootstrapperComponent {
9+
waitCallback: { (): Observable<void> } = () => {
10+
return this.wait(this.action, 'Async button');
11+
}
12+
13+
action(name: string): void {
14+
console.log('Action: ' + name);
15+
}
16+
17+
wait(callback, name): Observable<void> {
18+
return Observable.of(null).do(() => callback(name)).delay(1000);
19+
}
20+
}

0 commit comments

Comments
 (0)