fix(platform-server): support svg elements with namespaced attributes (#15101)

This commit is contained in:
vikerman 2017-03-14 15:40:55 -07:00 committed by Chuck Jazdzewski
parent 80649ea03c
commit f093501501
2 changed files with 28 additions and 3 deletions

View File

@ -453,11 +453,15 @@ export class Parse5DomAdapter extends DomAdapter {
hasAttribute(element: any, attribute: string): boolean { hasAttribute(element: any, attribute: string): boolean {
return element.attribs && element.attribs[attribute] != null; return element.attribs && element.attribs[attribute] != null;
} }
hasAttributeNS(element: any, ns: string, attribute: string): boolean { throw 'not implemented'; } hasAttributeNS(element: any, ns: string, attribute: string): boolean {
return this.hasAttribute(element, attribute);
}
getAttribute(element: any, attribute: string): string { getAttribute(element: any, attribute: string): string {
return this.hasAttribute(element, attribute) ? element.attribs[attribute] : null; return this.hasAttribute(element, attribute) ? element.attribs[attribute] : null;
} }
getAttributeNS(element: any, ns: string, attribute: string): string { throw 'not implemented'; } getAttributeNS(element: any, ns: string, attribute: string): string {
return this.getAttribute(element, attribute);
}
setAttribute(element: any, attribute: string, value: string) { setAttribute(element: any, attribute: string, value: string) {
if (attribute) { if (attribute) {
element.attribs[attribute] = value; element.attribs[attribute] = value;
@ -467,7 +471,7 @@ export class Parse5DomAdapter extends DomAdapter {
} }
} }
setAttributeNS(element: any, ns: string, attribute: string, value: string) { setAttributeNS(element: any, ns: string, attribute: string, value: string) {
throw 'not implemented'; this.setAttribute(element, attribute, value);
} }
removeAttribute(element: any, attribute: string) { removeAttribute(element: any, attribute: string) {
if (attribute) { if (attribute) {

View File

@ -70,6 +70,18 @@ class MyAsyncServerApp {
class AsyncServerModule { class AsyncServerModule {
} }
@Component({selector: 'app', template: '<svg><use xlink:href="#clear"></use></svg>'})
class SVGComponent {
}
@NgModule({
declarations: [SVGComponent],
imports: [BrowserModule.withServerTransition({appId: 'svg-server'}), ServerModule],
bootstrap: [SVGComponent]
})
class SVGServerModule {
}
@Component({selector: 'app', template: `Works!`, styles: [':host { color: red; }']}) @Component({selector: 'app', template: `Works!`, styles: [':host { color: red; }']})
class MyStylesApp { class MyStylesApp {
} }
@ -322,6 +334,15 @@ export function main() {
called = true; called = true;
}); });
}))); })));
it('works with SVG elements', async(() => {
renderModule(SVGServerModule, {document: doc}).then(output => {
expect(output).toBe(
'<html><head></head><body><app ng-version="0.0.0-PLACEHOLDER">' +
'<svg><use xlink:href="#clear"></use></svg></app></body></html>');
called = true;
});
}));
}); });
describe('http', () => { describe('http', () => {