有没有办法创建那些 HTML 模板替换自定义选择器的组件? [英] is there way to create component those HTML template replaces custom selector?

查看:23
本文介绍了有没有办法创建那些 HTML 模板替换自定义选择器的组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自学 angular2.我试图构建组件trigger-resize",我想将其呈现为:

i'm trying to teach myself angular2. I trying to build component "trigger-resize", which i want to render as :

<a class="hidden-xs" href="">
    <em class="fa fa-navicon"></em>
</a>

而不是:

<trigger-resize>

   <a class="hidden-xs" href="">
      <em class="fa fa-navicon"></em>
   </a>
</trigger-resize>

(我不希望自定义选择器呈现)

(i dont want custom selector to render)

在 angular 1 中.我知道可以通过replace:true"选项来实现,但是可以在 angular2 中实现吗?

In angular 1. i know it would be achieved by "replace:true" option, but is it possible to achieve it in angular2?

亲切的问候

推荐答案

一种方法是使用属性

<a triggerResize class="hidden-xs" href=""></a>

其中有一个组件

@Component({
    selector : 'a[triggerResize]', //select all <a> tags with triggerResize attribute
    template : '<em class="fa fa-navicon"></em>'
})

CamelCase 属性现在是 angular2 中自定义属性的正确语法

CamelCase attributes are the proper syntax now for custom attributes in angular2

这篇关于有没有办法创建那些 HTML 模板替换自定义选择器的组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆