2

I’m using the angular rendering engine to render material components. But when I render the controls (in my case Cards => mat-card) they do not have any style. So everything that comes with the prebuilt-themes(node_modules\@angular\material\prebuilt-themes ). no style

When I add a card by hand =>

<mat-card> test</mat-card>

And set the class Attribute at the rendering process it works =>

renderer.setAttribute(matCard , "class", "mat-card");

with style

So the Question is, how can I tell angular that it has to add the styles to the Page?

Here is the complete code I’m using to create the control

var matCard = renderer.createElement('mat-card');
renderer.setAttribute(matCard , "class", "mat-card");
const matCardInner = renderer.createText('Dynamic card!');          
renderer.appendChild(matCard, matCardInner);
const container = targetEl.nativeElement;
renderer.appendChild(container, matCard);

Thanks for your help Michael

1
  • Why not simply use *ngFor ? Commented Feb 16, 2018 at 15:39

1 Answer 1

1

Got the answer on Github.

The solution was to pack the angular material components into own wrapper components in my project and then create the wrapper components. Then the styles are always available and I am able to add my own additional functions like validation in the components.

So for my Project I have now a component for each material design component I'm using.

Sign up to request clarification or add additional context in comments.

Comments

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.