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

Function applyStyling

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

Source from the content-addressed store, hash-verified

1133 * otherwise).
1134 */
1135export function applyStyling(
1136 renderer: Renderer,
1137 isClassBased: boolean,
1138 rNode: RElement,
1139 prop: string,
1140 value: any,
1141) {
1142 if (isClassBased) {
1143 // We actually want JS true/false here because any truthy value should add the class
1144 if (!value) {
1145 renderer.removeClass(rNode, prop);
1146 } else {
1147 renderer.addClass(rNode, prop);
1148 }
1149 } else {
1150 let flags = prop.indexOf('-') === -1 ? undefined : (RendererStyleFlags2.DashCase as number);
1151 if (value == null /** || value === undefined */) {
1152 renderer.removeStyle(rNode, prop, flags);
1153 } else {
1154 // A value is important if it ends with `!important`. The style
1155 // parser strips any semicolons at the end of the value.
1156 const isImportant = typeof value === 'string' ? value.endsWith('!important') : false;
1157
1158 if (isImportant) {
1159 // !important has to be stripped from the value for it to be valid.
1160 value = value.slice(0, -10);
1161 flags! |= RendererStyleFlags2.Important;
1162 }
1163
1164 renderer.setStyle(rNode, prop, value, flags);
1165 }
1166 }
1167}

Callers 1

updateStylingFunction · 0.90

Calls 6

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

Tested by

no test coverage detected