0

I am trying to plug in some html content in an Angular component The components fetches the HTML using a service call and sets the property which is bound to innerHtml of the div.

There is a bunch of styles that needs to be set for this html plug, as given below in the scss content.

But I am not sure how to do this .... tried ngStyle and ngClass to return the style and use in the div but that did not work. Can anyone please tell me how to apply style for innerHtml? - Thanks

  <div class [innerHTML]="html"></div>

  private fetchEmail() {
    const d = this._intl.formatDate(this.today, 'yyyy-MM-dd');
    this._vmService.getVariatioMarginEmail(d).subscribe(e => {
      if (!isUndefined(e) || e.length > 0) {
        this.html = e.html;
      }
    });
  }


.table {
    border-collapse: collapse;
    border: 1px solid #999;
    font: normal 11px verdana, arial, helvetica, sans-serif;
    color: #F6ECF0;
    background: transparent;
  }

  th {
    border: 1px solid #999;
    text-align: left;
    vertical-align: middle;
    font-weight: 700;
    background: #333a56;
    color: #fff;
    padding: 5px 10px;
  }

  td {
    border-collapse: collapse;
    border: 1px solid #999;
    padding: 5px 10px;
    color: #555;
  }

  tbody td a {
    background: transparent;
    text-decoration: none;
    color: #F6ECF0;
  }

  a {
    font: normal 11px verdana, arial, helvetica, sans-serif;
  }

1 Answer 1

1

I have to use a class and ngdeep

<div class ='emailClas" [innerHTML]="html"></div>

    .emailClass ::ng-deep table {
    border-collapse: collapse;
    border: 1px solid #999;
    font: normal 11px verdana, arial, helvetica, sans-serif;
    color: #F6ECF0;
    background: transparent;
  }

  .emailClass ::ng-deep  th {
    border: 1px solid #999;
    text-align: left;
    vertical-align: middle;
    font-weight: 700;
    background: #333a56;
    color: #fff;
    padding: 5px 10px;
  }

  .emailClass ::ng-deep td {
    border-collapse: collapse;
    border: 1px solid #999;
    padding: 5px 10px;
    color: #555;
  }

  .emailClass ::ng-deep  tbody td a {
    background: transparent;
    text-decoration: none;
    color: #F6ECF0;
  }

  .emailClass ::ng-deep  a {
    font: normal 11px verdana, arial, helvetica, sans-serif;
  }
Sign up to request clarification or add additional context in comments.

2 Comments

It appears ng-deep is undocumented and who know if it will still work in future
ng-deep is documented, angular.io/guide/component-styles#deprecated-deep--and-ng-deep . And it will work until the arrival of appropriate alternative

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.