Can I use ngClass on the ng-template?
See original GitHub issueId like to add a class to a menu item conditionally.
<ng-template contextMenuItem (execute)="doSomething($event.item)" [ngClass]="{'first': true}">
but get a console error: TypeError: Cannot read property ‘add’ of undefined
Even better, I’d like to reference the item’s properties, like
[ngClass]="{'first': $event.item.isSnapToGrid}"
but I get: ReferenceError: $event is not defined
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to style angular ng-template selector - Stack Overflow
using #other_content as ID in my .css file; adding a class to <ng-template>; styling all <td> tags. It's not working and after ...
Read more >Angular ngClass and ngStyle: The Complete Guide
The ngClass directive will take an expression that will be used to determine which state styles to apply at a given time to...
Read more >Angular NgClass Example – How to Add Conditional CSS ...
ngClass is a directive in Angular [https://angular.io/api/common/NgClass] that adds and removes CSS classes on an HTML element.
Read more >NgStyle & NgClass • Angular - codecraft.tv
The NgClass directive allows you to set the CSS class dynamically for a DOM element. Tip. The NgClass directive will feel very similar...
Read more >NgClass - Angular
string - the CSS classes listed in the string (space delimited) are added, · Array - the CSS classes declared as Array elements...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You can’t put element attributes on an
<ng-template>since it doesn’t map to an actual DOM element. The best you can do is this:If all you want to do is write a css rule for the first context menu item, you can do that without a class.
In you css file =>
.loading { margin: 10% 0 0 50%; }In the HTML file =>
OR In you css file =>
.loading { margin: 10% 0 0 50%; }In the HTML file =>
In the component file .ts
In the Interface file declare custom type property