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

Function applyStyling

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

Source from the content-addressed store, hash-verified

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

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