angularjs – 角度2组件可以与属性选择器一起使用吗?
我们目前有一个现有的小型Angular 1项目,该项目在内部部署Sharepoint 2013环境中使用。对于我们内容的大部分内容,我们在Sharepoint环境中使用发布页面。
使用Angular 1,我们可以定义要限制的指令:匹配属性名称,标记名称,注释或类名称。我们创建的大多数指令都是属性或标记名称。首选项将是标记名称,但Sharepoint上的发布平台会删除未知元素。这意味着我们留下了使用属性,以便将我们的指令带入发布页面。但是使用Angular 2,我只看到了由标签名称实现的组件。 Angular 2是否可以使用属性名称来使用我们的组件?由于Sharepoint发布平台的限制,这是我们的要求。 谢谢。
是的,@ Component装饰器的selector属性是
CSS selector(或其子集):
这样你就可以使用[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包含所有三个的例子。
是。但请注意引用。在当前实现中,selector [attributeName =“attributeValue”]实际上匹配< sometag attributeName ='“attributeValue”'>,因此在提交此方法之前进行测试。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |