Skip to content

Commit 3f784b5

Browse files
authored
Merge pull request #141 from cal-smith/master
fix(modal): upgrade to newer injector api
2 parents 763dd52 + 8174acf commit 3f784b5

File tree

3 files changed

+13
-24
lines changed

3 files changed

+13
-24
lines changed

src/modal/alert-modal.component.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import {
22
Component,
33
Injector,
4-
ElementRef
4+
ElementRef,
5+
Inject
56
} from "@angular/core";
67
import {
78
trigger,
@@ -71,7 +72,7 @@ import Modal from "./modal.decorator";
7172
ibmButton="{{button.type}}"
7273
(click)="buttonClicked(i)"
7374
[id]="button.id"
74-
[attr.modal-primary-focus]="button.type.indexOf('primary') !== -1 ? '' : null">
75+
[attr.modal-primary-focus]="(button.type.indexOf('primary') !== -1 ? '' : null)">
7576
{{button.text}}
7677
</button>
7778
</ng-container>
@@ -80,27 +81,18 @@ import Modal from "./modal.decorator";
8081
`
8182
})
8283
export class AlertModalComponent {
83-
modalType = "default";
84-
modalLabel: string;
85-
modalTitle: string;
86-
modalContent: string;
87-
buttons = [];
88-
8984
/**
9085
* Creates an instance of `AlertModalComponent`.
9186
* @param {ModalService} modalService
9287
* @memberof AlertModalComponent
9388
*/
9489
constructor(
95-
private injector: Injector,
96-
private elementRef: ElementRef
90+
@Inject("modalType") public modalType = "default",
91+
@Inject("modalLabel") public modalLabel: string,
92+
@Inject("modalTitle") public modalTitle: string,
93+
@Inject("modalContent") public modalContent: string,
94+
@Inject("buttons") public buttons = []
9795
) {
98-
this.modalType = this.injector.get("modalType");
99-
this.modalLabel = this.injector.get("modalLabel");
100-
this.modalTitle = this.injector.get("modalTitle");
101-
this.modalContent = this.injector.get("modalContent");
102-
103-
this.buttons = this.injector.get("buttons") || [];
10496
for (let i = 0; i < this.buttons.length; i++) {
10597
const button = this.buttons[i];
10698
if (!button.id) {

src/modal/modal.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import {
22
ComponentFactoryResolver,
33
ComponentRef,
44
ReflectiveInjector,
5-
ViewContainerRef
5+
ViewContainerRef,
6+
Injector
67
} from "@angular/core";
78
import { ModalComponent } from "./modal.component";
89
import { ModalPlaceholderService } from "./modal-placeholder.service";
@@ -47,8 +48,7 @@ export class ModalService {
4748
data = Object.assign({}, defaults, data);
4849

4950
const inputProviders = Object.keys(data.inputs).map(inputName => ({provide: inputName, useValue: data.inputs[inputName]}));
50-
const resolvedInputs = ReflectiveInjector.resolve(inputProviders);
51-
const injector = ReflectiveInjector.fromResolvedProviders(resolvedInputs, this.placeholder.viewContainerRef.parentInjector);
51+
const injector = Injector.create(inputProviders);
5252
const factory = this.resolver.resolveComponentFactory(data.component);
5353
let focusedElement = document.activeElement;
5454
let component = factory.create(injector);

src/modal/modal.stories.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { withKnobs, text, select } from "@storybook/addon-knobs/angular";
44
import { TranslateModule } from "@ngx-translate/core";
55

66
import { ModalModule } from "../";
7-
import { Component, Injector, Input } from "@angular/core";
7+
import { Component, Input, Inject } from "@angular/core";
88
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
99
import { Modal, ModalService } from "../";
1010

@@ -25,10 +25,7 @@ import { Modal, ModalService } from "../";
2525
`
2626
})
2727
class SampleModalComponent {
28-
modalText: string;
29-
constructor(private injector: Injector) {
30-
this.modalText = this.injector.get("modalText");
31-
}
28+
constructor(@Inject("modalText") public modalText) {}
3229
}
3330

3431
@Modal()

0 commit comments

Comments
 (0)