Angular: CSS class usage within innerHtml of a cell
up vote
2
down vote
favorite
I am fighting with this CSS issue, or angular, ...
The problem is that the CSS class used in a DIV element of my table cell is ignored.
I copied the basic example of https://material.angular.io/components/table/examples as this is what I want to use.
within the css file I added:
.test-css {
color: orange;
}
then I modified the html template in order for one cell to call a method from my component class to get the innerHTML code:
<td mat-cell *matCellDef="let element" [innerHtml]="getInnerHtml(element)"</td>
The method looks like that:
public getInnerHtml(element) {
return `<div class="test-css">${element.name}</div>`;
}
The name is not displayed in orange.
If I apply the the test-css to the cell itself in the component template:
<td mat-cell *matCellDef="let element" class="test-css [innerHtml]="getInnerHtml(element)"</td>
then the column correctly appear in orange.
If I change on the component encapsulation to None, it works but the overall table layout is completely disturbed.
So I expect some issue in the way the innerHtml is interpreted.
Any idea if there is a way to solve it and to have the innerHtml correctly interpreted?
Thanks
css angular innerhtml
add a comment |
up vote
2
down vote
favorite
I am fighting with this CSS issue, or angular, ...
The problem is that the CSS class used in a DIV element of my table cell is ignored.
I copied the basic example of https://material.angular.io/components/table/examples as this is what I want to use.
within the css file I added:
.test-css {
color: orange;
}
then I modified the html template in order for one cell to call a method from my component class to get the innerHTML code:
<td mat-cell *matCellDef="let element" [innerHtml]="getInnerHtml(element)"</td>
The method looks like that:
public getInnerHtml(element) {
return `<div class="test-css">${element.name}</div>`;
}
The name is not displayed in orange.
If I apply the the test-css to the cell itself in the component template:
<td mat-cell *matCellDef="let element" class="test-css [innerHtml]="getInnerHtml(element)"</td>
then the column correctly appear in orange.
If I change on the component encapsulation to None, it works but the overall table layout is completely disturbed.
So I expect some issue in the way the innerHtml is interpreted.
Any idea if there is a way to solve it and to have the innerHtml correctly interpreted?
Thanks
css angular innerhtml
If you apply ::ng-deep to your css, does that help? Details here
– dmcgrandle
Nov 9 at 18:54
Thanks so much, it works! The documentation seems to mention that it is deprecated, so I hope it will survive.
– Ovomaltin
Nov 9 at 20:17
Yes, it is deprecated which is why I didn't suggest it as an answer (just as a comment). However there isn't a good replacement that I know of, other than to change the encapsulation which as you found out has other effects.
– dmcgrandle
Nov 9 at 20:23
Thanks again. If anyone reading this has an option to replace the deprecated ::ng-deep I would be glad to try it.
– Ovomaltin
Nov 9 at 21:13
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I am fighting with this CSS issue, or angular, ...
The problem is that the CSS class used in a DIV element of my table cell is ignored.
I copied the basic example of https://material.angular.io/components/table/examples as this is what I want to use.
within the css file I added:
.test-css {
color: orange;
}
then I modified the html template in order for one cell to call a method from my component class to get the innerHTML code:
<td mat-cell *matCellDef="let element" [innerHtml]="getInnerHtml(element)"</td>
The method looks like that:
public getInnerHtml(element) {
return `<div class="test-css">${element.name}</div>`;
}
The name is not displayed in orange.
If I apply the the test-css to the cell itself in the component template:
<td mat-cell *matCellDef="let element" class="test-css [innerHtml]="getInnerHtml(element)"</td>
then the column correctly appear in orange.
If I change on the component encapsulation to None, it works but the overall table layout is completely disturbed.
So I expect some issue in the way the innerHtml is interpreted.
Any idea if there is a way to solve it and to have the innerHtml correctly interpreted?
Thanks
css angular innerhtml
I am fighting with this CSS issue, or angular, ...
The problem is that the CSS class used in a DIV element of my table cell is ignored.
I copied the basic example of https://material.angular.io/components/table/examples as this is what I want to use.
within the css file I added:
.test-css {
color: orange;
}
then I modified the html template in order for one cell to call a method from my component class to get the innerHTML code:
<td mat-cell *matCellDef="let element" [innerHtml]="getInnerHtml(element)"</td>
The method looks like that:
public getInnerHtml(element) {
return `<div class="test-css">${element.name}</div>`;
}
The name is not displayed in orange.
If I apply the the test-css to the cell itself in the component template:
<td mat-cell *matCellDef="let element" class="test-css [innerHtml]="getInnerHtml(element)"</td>
then the column correctly appear in orange.
If I change on the component encapsulation to None, it works but the overall table layout is completely disturbed.
So I expect some issue in the way the innerHtml is interpreted.
Any idea if there is a way to solve it and to have the innerHtml correctly interpreted?
Thanks
css angular innerhtml
css angular innerhtml
asked Nov 9 at 15:26
Ovomaltin
111
111
If you apply ::ng-deep to your css, does that help? Details here
– dmcgrandle
Nov 9 at 18:54
Thanks so much, it works! The documentation seems to mention that it is deprecated, so I hope it will survive.
– Ovomaltin
Nov 9 at 20:17
Yes, it is deprecated which is why I didn't suggest it as an answer (just as a comment). However there isn't a good replacement that I know of, other than to change the encapsulation which as you found out has other effects.
– dmcgrandle
Nov 9 at 20:23
Thanks again. If anyone reading this has an option to replace the deprecated ::ng-deep I would be glad to try it.
– Ovomaltin
Nov 9 at 21:13
add a comment |
If you apply ::ng-deep to your css, does that help? Details here
– dmcgrandle
Nov 9 at 18:54
Thanks so much, it works! The documentation seems to mention that it is deprecated, so I hope it will survive.
– Ovomaltin
Nov 9 at 20:17
Yes, it is deprecated which is why I didn't suggest it as an answer (just as a comment). However there isn't a good replacement that I know of, other than to change the encapsulation which as you found out has other effects.
– dmcgrandle
Nov 9 at 20:23
Thanks again. If anyone reading this has an option to replace the deprecated ::ng-deep I would be glad to try it.
– Ovomaltin
Nov 9 at 21:13
If you apply ::ng-deep to your css, does that help? Details here
– dmcgrandle
Nov 9 at 18:54
If you apply ::ng-deep to your css, does that help? Details here
– dmcgrandle
Nov 9 at 18:54
Thanks so much, it works! The documentation seems to mention that it is deprecated, so I hope it will survive.
– Ovomaltin
Nov 9 at 20:17
Thanks so much, it works! The documentation seems to mention that it is deprecated, so I hope it will survive.
– Ovomaltin
Nov 9 at 20:17
Yes, it is deprecated which is why I didn't suggest it as an answer (just as a comment). However there isn't a good replacement that I know of, other than to change the encapsulation which as you found out has other effects.
– dmcgrandle
Nov 9 at 20:23
Yes, it is deprecated which is why I didn't suggest it as an answer (just as a comment). However there isn't a good replacement that I know of, other than to change the encapsulation which as you found out has other effects.
– dmcgrandle
Nov 9 at 20:23
Thanks again. If anyone reading this has an option to replace the deprecated ::ng-deep I would be glad to try it.
– Ovomaltin
Nov 9 at 21:13
Thanks again. If anyone reading this has an option to replace the deprecated ::ng-deep I would be glad to try it.
– Ovomaltin
Nov 9 at 21:13
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53228613%2fangular-css-class-usage-within-innerhtml-of-a-cell%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If you apply ::ng-deep to your css, does that help? Details here
– dmcgrandle
Nov 9 at 18:54
Thanks so much, it works! The documentation seems to mention that it is deprecated, so I hope it will survive.
– Ovomaltin
Nov 9 at 20:17
Yes, it is deprecated which is why I didn't suggest it as an answer (just as a comment). However there isn't a good replacement that I know of, other than to change the encapsulation which as you found out has other effects.
– dmcgrandle
Nov 9 at 20:23
Thanks again. If anyone reading this has an option to replace the deprecated ::ng-deep I would be glad to try it.
– Ovomaltin
Nov 9 at 21:13