You need to keep the styles/cssClass in TypeScript:
[example][1]:
[1]: https://stackblitz.com/edit/angular-9vnaqy?
Just For your case you need to create a common interface or class
class theItems{
name:String;
styleClass:String;
}
or maybe you want to handle it with a dynamic class depends on how you want to solve the HTML side.
dones:theItems[]=[
{
name: 'Get to work',
styleClass:"grid-column: 2/5; background-color: red;",
},
{
name: 'Brush teeth',
styleClass:"grid-column: 2/5; background-color: red;",
},
{
name: 'Take a shower',
styleClass:"grid-column: 2/5; background-color: red;",
},
];
todos:theItems[]=[
{
name: 'Get to work',
styleClass:"grid-column: 1/11; margin: 0 10px; background-color: #00B7A8;",
},
{
name: 'Pick up groceries',
styleClass:"grid-column: 1/11; margin: 0 10px; background-color: #00B7A8;",
},
{
name: 'Go home',
styleClass:"grid-column: 1/11; margin: 0 10px; background-color: #00B7A8;",
},
{
name: 'Fall asleep',
styleClass:"grid-column: 1/11; margin: 0 10px; background-color: #00B7A8;",
},
];
Pre populate the list of objects in array and connect the cdkDropListData with the desired array.
Now be assure if you want to use css in typescript you must clean it for the DOM
safeCss(style) {
return this.doms.bypassSecurityTrustStyle(style);
}
Or you can use only the css/SCSS class name aswell.
finally use the sanitized css in Html element:
[style]="safeCss(item.styleClass)"
Feel free to comment with your thoughts, would appreciate it if accepted as an answer.
https://stackblitz.com/edit/angular-9vnaqy?