Formerly called ng2-inline-svg
Angular directive for inserting an SVG inline within an element, allowing for easily stylingwith CSS like fill: currentColor;
.
This is based on md-icon,except this is meant purely for inserting SVG files within an element, without the extra things likefont icons.
npm install --save ng-inline-svg
Add HttpClientModule
and InlineSVGModule
to your list of module imports:
import { HttpClientModule } from '@angular/common/http';
import { InlineSVGModule } from 'ng-inline-svg';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, HttpClientModule, InlineSVGModule.forRoot()],
bootstrap: [AppComponent]
})
class AppModule {}
The base URL will be automatically fetched based on your <base>
tag. If you want to configure the base URL manually, you can use the forRoot
function:
InlineSVGModule.forRoot({ baseUrl: 'https://mysite.com/myapp/' })
You can then use the directive in your templates:
@Component({
selector: 'app',
template: `
<div class="my-icon" aria-label="My icon" [inlineSVG]="'/img/image.svg'"></div>
`
})
export class AppComponent {}
The SVG file (if found) will be inserted inside the element with the [inlineSVG]
directive. Support for icons using the symbol
method is also supported (e.g. [inlineSVG]="'#shape-id'"
).
Property name | Type | Default | Description |
---|---|---|---|
cacheSVG | boolean | true |
Caches the SVG based on the absolute URL. Cache only persists for the (sessional) lifetime of the page. |
resolveSVGUrl | boolean | true |
Bypass logic that tries to determine the absolute URL using the page's or configured base URL. |
prepend | boolean | false |
Inserts before the first child instead of appending, overwrites replaceContents |
replaceContents | boolean | true |
Replaces the contents of the element with the SVG instead of just appending it to its children. |
injectComponent | boolean | false |
Injects an <inline-svg> component containing the SVG inside the element with the directive. |
setSVGAttributes | { [key: string]: any } |
Sets attributes on the SVG element. Runs after removeSVGAttributes . |
|
removeSVGAttributes | string[] | An array of attribute names to remove from all child elements within the SVG. | |
forceEvalStyles | boolean | false |
Forces embeded style tags' contents to be evaluated (for IE 11). |
evalScripts | 'always' , 'once' , 'none' |
'always' |
Whether to evaluate embedded scripts in the loaded SVG files. The SVGScriptEvalMode enum is also provided. |
fallbackImgUrl | string | URL for a regular image to be displayed as a fallback if the SVG fails to load. | |
fallbackSVG | string | SVG filename to be displayed as a fallback if the SVG fails to load. | |
onSVGLoaded | (svg: SVGElement, parent: Element | null) => SVGElement |
Lifecycle hook that allows the loaded SVG to be manipulated prior to insertion. |
Property name | Callback arguments | Description |
---|---|---|
onSVGInserted | e: SVGElement |
Emits the SVGElement post-insertion. |
onSVGFailed | e: any |
Emits when there is some error (e.g. embed SVG not supported, fetch failed, etc.) |
The SVG files can also be rendered server-side. For this to work, you have to set the baseURL
, since Angular needs to have an absolute URL to retrieve the files server-side and we're not able to get your baseURL automatically in a server-side environment. See manual for setting baseURL
above.
Here is one way to achieve this dynamically by adding an app initalizing service which sets the base URL based on the environment it runs.
app-server.module.ts:
import { NgModule, APP_INITIALIZER } from '@angular/core';
import { InlineSVGConfig } from 'ng-inline-svg';
import { SVGConfig } from './svg-config';
@NgModule({
providers: [
{ provide: InlineSVGConfig, useClass: SVGConfig }
]
})
export class AppServerModule {}
svg-config.ts:
import { Injectable, Inject } from '@angular/core';
import { InlineSVGConfig } from 'ng-inline-svg';
@Injectable()
export class SVGConfig extends InlineSVGConfig {
// Do what ever conditions you need to set this, e.g. checking for server-side rendering
// and only set baseURL when server-side rendered if you want.
constructor(...) {
super();
// When the server-side rendered app runs on localhost:3000, make sure baseURL is
// http://localhost:3000 and make sure the Express server is configured properly to
// allow the URL of the asset folders storing the SVG files.
this.baseUrl = 'http://localhost:3000';
// If you don't want the directive to run on the server side.
this.clientOnly = true;
// If you want to bypass your HttpClient interceptor chain when fetching SVGs.
this.bypassHttpClientInterceptorChain = true;
}
}
自己在创建angular项目的时候,使用ng-zorro UI组件库,遇到安装之后,不生效的问题,是没有正确引入,其实官方文档也提到了。 官网地址:https://ng.ant.design/docs/getting-started/zh 1. 安装脚手架工具# 使用 @angular/cli 前,务必确认 Node.js 已经升级到 v12.1 或以上,强烈建议升级至最新版本的 @angular
来到残差网络了。这周的作业最终是一个50层的残差网络,作业上说明了,只会进行两次迭代来测试代码,然而这两次就已经花了近十分钟的时间,所以如果要做完完整的二十次迭代要上小时(using CPU)。。所以后面就附带了他们已经训练好的二十次迭代之后的结果给我们演示一次结果……最终的准确率是86%。 放代码: import numpy as np from keras import layers from
描述 (Description) @import (inline)语句将CSS复制到输出CSS文件中而不进行处理。 当CSS文件不兼容时,这很有用。 尽管LESS支持大多数标准CSS,但某些地方不支持注释,如果不修改CSS,它将不支持所有已知的CSS黑客攻击。 即使@import (inline)不会处理CSS,它也会确保所有CSS都在一个文件中。 这是在1.5.0版本中发布的。 例子 (Exam
本文向大家介绍block、inline、inline-block的区别?相关面试题,主要包含被问及block、inline、inline-block的区别?时的应答技巧和注意事项,需要的朋友参考一下 参考回答: block元素会独占一行,多个block元素会各自新起一行。默认情况下,block元素宽度自动填满其父元素宽度。 block元素可以设置width,height属性。块级元素即使设置了宽度
描述 (Description) 内嵌标签被分成组内嵌的,使我们能够快速地将它们之间翻转。 例子 (Example) 下面的例子演示了使用上Framework7内嵌接片不同的内容之间的切换 - <!DOCTYPE html> <html> <head> <meta name = "viewport" content = "width = device-width, initial
Sphinx uses interpreted text roles to insert semantic markup into documents. They are written as :rolename:`content`. Note The default role (`content`) has no special meaning by default. You are free
将页面依赖的js、css、img资源嵌入到页面中去。 举例,如html页面中有如下外部css链接: <link href="css/style.css?__inline=true" rel="stylesheet" /> 运行grunt inline后,会被替换成内联样式。js也类似,而图片则会被转换成对应的base64字符串。 <style>/* contents of css/style.cs
This example shows you the inline editing capabilities of TinyMCE. The world’s first rich text editor in the cloud Have you heard about Tiny Cloud? It’s the first step in our journey to help you deliv