新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Angular教程:AngularSVG作為模板
SVG 作為模板
你可以在 Angular 應用程序中將 SVG 文件用作模板。當你使用 SVG 作為模板時,就可以像 HTML 模板一樣使用指令和綁定。使用這些功能,你可以動態(tài)生成交互式圖形。

我們提供的服務有:成都網(wǎng)站設計、成都網(wǎng)站建設、外貿(mào)網(wǎng)站建設、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認證、惠陽ssl等。為近千家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務,是有科學管理、有技術的惠陽網(wǎng)站制作公司
包含本章代碼片段的工作實例參閱現(xiàn)場演練 / 下載范例。
SVG 語法示例
以下示例展示了將 SVG 用作模板的語法。
import { Component } from '@angular/core';
@Component({
selector: 'app-svg',
templateUrl: './svg.component.svg',
styleUrls: ['./svg.component.css']
})
export class SvgComponent {
fillColor = '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.fillColor = `rgb(${r}, ${g}, $)`;
}
}要想查看屬性和事件綁定的實際效果,請把以下代碼添加到你的 ?svg.component.svg? 文件中:
這個例子使用了事件綁定語法 ?click()? 和屬性綁定語法(?[attr.fill]="fillColor"?)。
當前標題:創(chuàng)新互聯(lián)Angular教程:AngularSVG作為模板
分享鏈接:http://www.dlmjj.cn/article/djjdpsj.html


咨詢
建站咨詢
