()
| 199 | */ |
| 200 | // TODO: replace null by undefined in the return type |
| 201 | get attributes(): {[key: string]: string | null} { |
| 202 | const attributes: {[key: string]: string | null} = {}; |
| 203 | const element = this.nativeElement as Element | undefined; |
| 204 | |
| 205 | if (!element) { |
| 206 | return attributes; |
| 207 | } |
| 208 | |
| 209 | const context = getLContext(element)!; |
| 210 | const lView = context ? context.lView : null; |
| 211 | |
| 212 | if (lView === null) { |
| 213 | return {}; |
| 214 | } |
| 215 | |
| 216 | const tNodeAttrs = (lView[TVIEW].data[context.nodeIndex] as TNode).attrs; |
| 217 | const lowercaseTNodeAttrs: string[] = []; |
| 218 | |
| 219 | // For debug nodes we take the element's attribute directly from the DOM since it allows us |
| 220 | // to account for ones that weren't set via bindings (e.g. ViewEngine keeps track of the ones |
| 221 | // that are set through `Renderer2`). The problem is that the browser will lowercase all names, |
| 222 | // however since we have the attributes already on the TNode, we can preserve the case by going |
| 223 | // through them once, adding them to the `attributes` map and putting their lower-cased name |
| 224 | // into an array. Afterwards when we're going through the native DOM attributes, we can check |
| 225 | // whether we haven't run into an attribute already through the TNode. |
| 226 | if (tNodeAttrs) { |
| 227 | let i = 0; |
| 228 | while (i < tNodeAttrs.length) { |
| 229 | const attrName = tNodeAttrs[i]; |
| 230 | |
| 231 | // Stop as soon as we hit a marker. We only care about the regular attributes. Everything |
| 232 | // else will be handled below when we read the final attributes off the DOM. |
| 233 | if (typeof attrName !== 'string') break; |
| 234 | |
| 235 | const attrValue = tNodeAttrs[i + 1]; |
| 236 | attributes[attrName] = attrValue as string; |
| 237 | lowercaseTNodeAttrs.push(attrName.toLowerCase()); |
| 238 | |
| 239 | i += 2; |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | for (const attr of element.attributes) { |
| 244 | // Make sure that we don't assign the same attribute both in its |
| 245 | // case-sensitive form and the lower-cased one from the browser. |
| 246 | if (!lowercaseTNodeAttrs.includes(attr.name)) { |
| 247 | attributes[attr.name] = attr.value; |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | return attributes; |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * The inline styles of the DOM element. |
nothing calls this directly
no test coverage detected