Complete the code to define a component with inline styles.
import { Component } from '@angular/core'; @Component({ selector: 'app-box', template: `<div class=\"box\">Hello</div>`, styles: [[1]] }) export class BoxComponent {}
The styles property expects an array of strings with CSS code. Using backticks allows multi-line CSS.
Complete the code to set the component's encapsulation to None.
import { Component, [1] } from '@angular/core'; @Component({ selector: 'app-no-encap', template: `<p>No encapsulation</p>`, encapsulation: [1].None }) export class NoEncapComponent {}
The ViewEncapsulation enum controls style encapsulation modes in Angular components.
Fix the error in the component decorator to properly apply styles with encapsulation.
@Component({
selector: 'app-style-fix',
template: `<h1>Title</h1>`,
styles: [1],
encapsulation: ViewEncapsulation.Emulated
})
export class StyleFixComponent {}The styles property must be an array of strings, so the CSS should be inside an array with backticks for multi-line support.
Fill both blanks to create a component with external styles and Shadow DOM encapsulation.
import { Component, [1] } from '@angular/core'; @Component({ selector: 'app-shadow', templateUrl: './shadow.component.html', styleUrls: ['./shadow.component.css'], encapsulation: [2] }) export class ShadowComponent {}
To use Shadow DOM encapsulation, import ViewEncapsulation and set encapsulation to ViewEncapsulation.ShadowDom.
Fill all three blanks to define a component with inline styles, Emulated encapsulation, and a template.
import { Component, [1] } from '@angular/core'; @Component({ selector: 'app-inline', template: [2], styles: [[3]], encapsulation: [1].Emulated }) export class InlineComponent {}
Use ViewEncapsulation for encapsulation, backticks for the template string, and backticks inside an array for styles.