MCPcopy Create free account
hub / github.com/angular/angular / applyStyling

Function applyStyling

packages/core/src/render3/node_manipulation.ts:1110–1142  ·  view source on GitHub ↗
(
  renderer: Renderer,
  isClassBased: boolean,
  rNode: RElement,
  prop: string,
  value: any,
)

Source from the content-addressed store, hash-verified

1108 * otherwise).
1109 */
1110export function applyStyling(
1111 renderer: Renderer,
1112 isClassBased: boolean,
1113 rNode: RElement,
1114 prop: string,
1115 value: any,
1116) {
1117 if (isClassBased) {
1118 // We actually want JS true/false here because any truthy value should add the class
1119 if (!value) {
1120 renderer.removeClass(rNode, prop);
1121 } else {
1122 renderer.addClass(rNode, prop);
1123 }
1124 } else {
1125 let flags = prop.indexOf('-') === -1 ? undefined : (RendererStyleFlags2.DashCase as number);
1126 if (value == null /** || value === undefined */) {
1127 renderer.removeStyle(rNode, prop, flags);
1128 } else {
1129 // A value is important if it ends with `!important`. The style
1130 // parser strips any semicolons at the end of the value.
1131 const isImportant = typeof value === 'string' ? value.endsWith('!important') : false;
1132
1133 if (isImportant) {
1134 // !important has to be stripped from the value for it to be valid.
1135 value = value.slice(0, -10);
1136 flags! |= RendererStyleFlags2.Important;
1137 }
1138
1139 renderer.setStyle(rNode, prop, value, flags);
1140 }
1141 }
1142}

Callers 1

updateStylingFunction · 0.90

Calls 5

indexOfMethod · 0.80
removeClassMethod · 0.65
addClassMethod · 0.65
removeStyleMethod · 0.65
setStyleMethod · 0.65

Tested by

no test coverage detected