My goal is to retrieve styles from an API and dynamically render components based on those styles.
import { Component } from '@angular/core';
import { StyleService } from "./style.service";
import { Style } from "./models/style";
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styles: [``]
})
export class AppComponent {
header: boolean;
footer: boolean;
style: string;
constructor(private styleService: StyleService) {}
ngOnInit() {
this.retrieveStyles()
}
retrieveStyles() {
this.styleService.getStyles({
business: 'sekeh'
})
.subscribe(
(val) => {
this.header = val.header,
this.footer = val.footer,
this.style = val.style
},
response => {
console.log("Error in POST call", response);
},
() => {
console.log("The POST observable has been completed.");
});
}
}
I have a couple of questions. Do I have access to the style property in the AppComponent class so that I can add new styles to the array? Alternatively, can I store the API styles in a variable and then set the styles property to that variable?