docs: added svg example (#30559)

Fixes #30441

PR Close #30559
This commit is contained in:
Santosh Yadav
2019-06-26 11:46:04 +05:30
committed by Alex Rickabaugh
parent 261dc04d8e
commit c6b29f4c6d
5 changed files with 51 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import { ClickDirective, ClickDirective2 } from './click.directive';
import { HeroFormComponent } from './hero-form.component';
import { heroSwitchComponents } from './hero-switch.components';
import { SizerComponent } from './sizer.component';
import { SvgComponent } from './svg.component';
@NgModule({
imports: [
@ -22,7 +23,8 @@ import { SizerComponent } from './sizer.component';
heroSwitchComponents,
ClickDirective,
ClickDirective2,
SizerComponent
SizerComponent,
SvgComponent
],
bootstrap: [ AppComponent ]
})

View File

@ -0,0 +1,4 @@
svg {
display: block;
width: 100%;
}

View File

@ -0,0 +1,6 @@
<svg>
<g>
<rect x="0" y="0" width="100" height="100" [attr.fill]="fill" (click)="changeColor()" />
<text x="120" y="50">click the rectangle to change the fill color</text>
</g>
</svg>

After

Width:  |  Height:  |  Size: 196 B

View File

@ -0,0 +1,17 @@
import { Component } from '@angular/core';
@Component({
selector: 'app-svg',
templateUrl: './svg.component.svg',
styleUrls: ['./svg.component.css']
})
export class SvgComponent {
fill = 'rgb(255, 0, 0)';
changeColor() {
const r = Math.floor(Math.random() * 256);
const g = Math.floor(Math.random() * 256);
const b = Math.floor(Math.random() * 256);
this.fill = `rgb(${r}, ${g}, ${b})`;
}
}