小编tom*_*bak的帖子

Angular2 SVG xlink:href

我有用于渲染SVG图标的组件:

import {Component, Directive} from 'angular2/core';
import {COMMON_DIRECTIVES} from 'angular2/common';

@Component({
  selector: '[icon]',
  directives: [COMMON_DIRECTIVES],
  template: `<svg role="img" class="o-icon o-icon--large">
                <use [xlink:href]="iconHref"></use>
              </svg>{{ innerText }}`
})
export class Icon {
  iconHref: string = 'icons/icons.svg#menu-dashboard';
  innerText: string = 'Dashboard';
}
Run Code Online (Sandbox Code Playgroud)

这会触发错误:

EXCEPTION: Template parse errors:
  Can't bind to 'xlink:href' since it isn't a known native property ("<svg role="img" class="o-icon o-icon--large">
<use [ERROR ->][xlink:href]=iconHref></use>
  </svg>{{ innerText }}"): SvgIcon@1:21
Run Code Online (Sandbox Code Playgroud)

我该如何设置动态xlink:href

angular2-template angular

38
推荐指数
1
解决办法
2万
查看次数

如何在 Angular2 中禁用部分模板的模板绑定?

我想{{ name }}在 Angular 2 模板中显示字符串。

如何禁用部分模板的模板绑定?

angular2-template angular

5
推荐指数
1
解决办法
1065
查看次数

标签 统计

angular ×2

angular2-template ×2