加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 角度2组件可以与属性选择器一起使用吗?

发布时间:2020-12-17 08:01:17 所属栏目:安全 来源:网络整理
导读:我们目前有一个现有的小型Angular 1项目,该项目在内部部署Sharepoint 2013环境中使用。对于我们内容的大部分内容,我们在Sharepoint环境中使用发布页面。 使用Angular 1,我们可以定义要限制的指令:匹配属性名称,标记名称,注释或类名称。我们创建的大多
我们目前有一个现有的小型Angular 1项目,该项目在内部部署Sharepoint 2013环境中使用。对于我们内容的大部分内容,我们在Sharepoint环境中使用发布页面。

使用Angular 1,我们可以定义要限制的指令:匹配属性名称,标记名称,注释或类名称。我们创建的大多数指令都是属性或标记名称。首选项将是标记名称,但Sharepoint上的发布平台会删除未知元素。这意味着我们留下了使用属性,以便将我们的指令带入发布页面。但是使用Angular 2,我只看到了由标签名称实现的组件。

Angular 2是否可以使用属性名称来使用我们的组件?由于Sharepoint发布平台的限制,这是我们的要求。

谢谢。

是的,@ Component装饰器的selector属性是 CSS selector(或其子集):

selector: '.cool-button:not(a)'

Specifies a CSS selector that identifies this directive within a template.
Supported selectors include element,[attribute],.class,and :not().
Does not support parent-child relationship selectors.

Source: 07001,which @Component inherits.

这样你就可以使用[name-of-the-attribute](即CSS attribute selector),例如:

@Component({
    selector: "[other-attr]",...
})
export class OtherAttrComponent {

Se demo plunker here

通常的方法是CSS type (AKA element or tag) selector:

@Component({
    selector: "some-tag",...
})

它匹配名称为some-tag的标签。

您甚至可以拥有与both a tag or an attribute匹配的组件:

@Component({
    selector: "other-both,[other-both]",template: `this is other-both ({{ value }})`
})
export class OtherBothComponent {

Demo plunker包含所有三个的例子。

Is [attributeName="attributeValue"] supported?

是。但请注意引用。在当前实现中,selector [attributeName =“attributeValue”]实际上匹配< sometag attributeName ='“attributeValue”'>,因此在提交此方法之前进行测试。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读