-
Notifications
You must be signed in to change notification settings - Fork 0
/
mat.service.ts
57 lines (51 loc) · 1.7 KB
/
mat.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* @license
* Copyright Neekware Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at http://neekware.com/license/MIT.html
*/
import { Injectable } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { MatIconRegistry } from '@angular/material';
@Injectable()
export class MatService {
constructor(private registry: MatIconRegistry, private sanitizer: DomSanitizer) {}
/**
* Loads icons with namespace
* @param iconList list of icons
*/
registerSvgIconsInNamespace(iconList, cacheBustingHash = null) {
// [
// ...
// {
// names: ['ca', 'CA'],
// namespace: 'flags',
// path: 'assets/images/svg/flags/ca.svg'
// },
// ]
iconList.forEach(icon => {
const path = cacheBustingHash ? `${icon.path}?${cacheBustingHash}` : icon.path;
const securePath = this.sanitizer.bypassSecurityTrustResourceUrl(path);
icon.names.forEach(name => {
this.registry.addSvgIconInNamespace(icon.namespace, name, securePath);
});
});
}
/**
* Loads icons set with no namespace
* @param iconPath path to icon set (ex: '/assets/fonts/mdi.svg')
*/
registerSvgIconSet(iconPath: string, cacheBustingHash = null) {
const path = cacheBustingHash ? `${iconPath}?${cacheBustingHash}` : iconPath;
const securePath = this.sanitizer.bypassSecurityTrustResourceUrl(iconPath);
this.registry.addSvgIconSet(securePath);
}
/**
* Register font alias
* @param font, alias (ex: 'fontawesome', 'fa')
*/
registerFontClassAlias(font: string, alias: string) {
this.registry.registerFontClassAlias(font, alias);
}
}