blob: 6c64015d34c722f72be55f12ba5032618beaa6aa [file] [log] [blame]
Matteo Scandolo6f45e262017-01-09 14:47:26 -08001export interface IXosAlertConfig {
2 type: string;
3 closeBtn?: boolean;
4 autoHide?: number;
5}
6
7class AlertCtrl {
8
9 static $inject = ['$timeout'];
10
11 public config: any;
12 public show: boolean;
13 public dismiss: () => void;
14
15 constructor (
16 private $timeout: ng.ITimeoutService
17 ) {
18
19 }
20
21 $onInit() {
22 if (!angular.isDefined(this.config)) {
23 throw new Error('[xosAlert] Please provide a configuration via the "config" attribute');
24 }
25
26 // default the value to true
27 this.show = this.show !== false;
28
29 this.dismiss = () => {
30 this.show = false;
31 };
32
33 console.log(this.config);
34 if (this.config.autoHide) {
35
36 let to = this.$timeout(() => {
37 this.dismiss();
38 this.$timeout.cancel(to);
39 }, this.config.autoHide);
40 }
41 }
42}
43
44export const xosAlert: angular.IComponentOptions = {
45 template: require('./alert.html'),
46 controllerAs: 'vm',
47 controller: AlertCtrl,
48 transclude: true,
49 bindings: {
50 config: '=',
51 show: '=',
52 }
53};