Skip to content

Commit fca28c2

Browse files
authored
Merge pull request #238 from zvonimirfras/master
fix(notification): Allow falsy `notificationObj`
2 parents 617acad + 52369cd commit fca28c2

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/notification/notification.component.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
EventEmitter,
66
ComponentRef,
77
ViewChild,
8-
OnInit,
98
HostBinding
109
} from "@angular/core";
1110

@@ -48,7 +47,7 @@ import { I18n } from "./../i18n/i18n.module";
4847
`,
4948
providers: [NotificationService]
5049
})
51-
export class Notification implements OnInit {
50+
export class Notification {
5251
/**
5352
* Can have `type`, `title`, and `message` members.
5453
*
@@ -57,7 +56,12 @@ export class Notification implements OnInit {
5756
* `message` is message for notification to display
5857
*
5958
*/
60-
@Input() notificationObj: NotificationContent;
59+
@Input() get notificationObj(): NotificationContent {
60+
return this._notificationObj;
61+
}
62+
set notificationObj(obj: NotificationContent) {
63+
this._notificationObj = Object.assign({}, this.defaultNotificationObj, obj);
64+
}
6165

6266
/**
6367
* Emits on close.
@@ -80,13 +84,15 @@ export class Notification implements OnInit {
8084
@HostBinding("class.bx--inline-notification--success") get isSuccess() { return this.notificationObj.type === "success"; }
8185
@HostBinding("class.bx--inline-notification--warning") get isWarning() { return this.notificationObj.type === "warning"; }
8286

83-
constructor(protected notificationService: NotificationService, protected i18n: I18n) {}
87+
protected defaultNotificationObj = {
88+
title: "",
89+
message: "",
90+
type: "info",
91+
closeLabel: this.i18n.get().NOTIFICATION.CLOSE_BUTTON
92+
};
93+
protected _notificationObj: NotificationContent = Object.assign({}, this.defaultNotificationObj);
8494

85-
ngOnInit() {
86-
if (!this.notificationObj.closeLabel) {
87-
this.notificationObj.closeLabel = this.i18n.get().NOTIFICATION.CLOSE_BUTTON;
88-
}
89-
}
95+
constructor(protected notificationService: NotificationService, protected i18n: I18n) {}
9096

9197
/**
9298
* Emits close event.

0 commit comments

Comments
 (0)