0
0
Angularframework~10 mins

ngStyle for dynamic styles in Angular - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to bind a dynamic background color using ngStyle.

Angular
<div [ngStyle]="{'background-color': [1]">Colored Box</div>
Drag options to blanks, or click blank then click option'
Acolor
BbackgroundColor
C'red'
DbgColor
Attempts:
3 left
💡 Hint
Common Mistakes
Using a CSS property name instead of the variable.
Putting the color value directly without quotes or variable.
2fill in blank
medium

Complete the code to apply multiple dynamic styles using ngStyle.

Angular
<div [ngStyle]="[1]">Styled Text</div>
Drag options to blanks, or click blank then click option'
A{'font-size.px': fontSize, 'color': textColor}
B'font-size.px: fontSize, color: textColor'
C[fontSize, textColor]
DfontSize + textColor
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of an object.
Using an array instead of an object.
3fill in blank
hard

Fix the error in the ngStyle binding to correctly apply a dynamic width.

Angular
<div [ngStyle]="{'width': [1] + 'px'}">Box</div>
Drag options to blanks, or click blank then click option'
A'widthValue'
BwidthValue
CwidthValue + 'px'
DwidthValuepx
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the variable name inside quotes making it a string literal.
Trying to concatenate inside the string key.
4fill in blank
hard

Fill both blanks to set dynamic height and background color using ngStyle.

Angular
<div [ngStyle]="{'height.px': [1], 'background-color': [2]">Box</div>
Drag options to blanks, or click blank then click option'
AboxHeight
BbgColor
C'blue'
DheightValue
Attempts:
3 left
💡 Hint
Common Mistakes
Using string literals instead of variables.
Mixing variable names between height and color.
5fill in blank
hard

Fill all three blanks to create a dynamic style object with font size, color, and margin.

Angular
<p [ngStyle]="{'font-size.px': [1], 'color': [2], 'margin.px': [3]">Text</p>
Drag options to blanks, or click blank then click option'
AfontSize
BtextColor
CmarginSize
Dpadding
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect variable names.
Confusing margin with padding.