пользовательские классы angular2 - PullRequest
0 голосов
/ 31 января 2019

Мы используем angular2-toaster в нашем проекте, и я столкнулся с проблемой, что не могу добавить пользовательский класс в экземпляр toaster.

Моя конфигурация тостера выглядит несколько иначе,и я хочу передать массив customClass с пользовательскими классами для тостера внутри.

showToaster(msg: string, customClass: string | string[]) {
   const toast: Toast = {
     type: customClass[0],
     body: msg
   };

   this.toasterService.pop(toast);
}

1 Ответ

0 голосов
/ 31 января 2019

Вы можете использовать ToasterConfig, а затем привязать его к своему toaster-container.

@Component({
  selector: 'my-app',
  template: `
    <div>
      <toaster-container [toasterconfig]="config"></toaster-container>
      <button (click)="popToast()">pop toast</button><br/>
    </div>
  `,
})
export class App {

  public config : ToasterConfig = new ToasterConfig({
    typeClasses: {
      class1: 'custom-class-1',
      class2: 'custom-class-2',
      class3: 'custom-class-3'
      /* goes on */
    }
  });

   /*
   other stuff of component 
   */
}

Затем вы можете использовать его так, как вы отправили:

showToaster(msg: string, customClass: string | string[]) {
   const toast: Toast = {
     type: customClass[0], // class1 or class2 or class3 or etc
     body: msg
   };

   this.toasterService.pop(toast);
}

Ссылки:

https://github.com/Stabzs/Angular2-Toaster/issues/110

https://github.com/Stabzs/Angular2-Toaster/blob/master/src/toaster-config.ts

http://plnkr.co/edit/gZTxVXD8lN3fibqhDYod?p=preview

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...