Angular 2 - sass库,用于覆盖组件css(不禁用封装)

时间:2018-04-27 08:31:55

标签: angular sass

我使用ngx-tabset,我可以设法覆盖css,但我必须手动添加类后缀[_ngcontent- ..]才能使其工作

所以我想创建一个我可以在任何地方使用的sass库,但它不使用与组件实例相同的后缀

我的覆盖样式(在文件sassLibrary / tabs.scss中)

public override Task<IQueryable<T>> AllAsync(ReadOptions options = null)
{
        var entry = this.Collection.AsQueryable(options);
        dynamic EntryList;
        EntryList = new Collection<Entry>();

        try
        {
            dynamic result = entry.ToList();

            if (result != null && result.Count != 0)
            {
                foreach (Entry entry in result)
                {
                    foreach (var item in entry.ModifiedEntries)
                    {
                        Attribute attr;
                        Entry obj = new Entry();
                        obj.Attributes = new Collection<Attribute>();

                        foreach (var attributes in item.Value.Attribute)
                        {
                            attr = new DflAttribute();
                            attr.Name = attributes.Key;
                            attr.Value = attributes.Value.Value;
                            obj.Attributes.Add(attr);
                        }

                        EntryList.Add(obj);
                    }
                }
            }

            return Task.FromResult(EntryList.AsQueryable());
        }
        catch (Exception ex)
        {
            throw Error.ToRepositoryException(ex, MethodBase.GetCurrentMethod());
        }
}

在html页面中,它看起来像

.tabset-style ul.tabset-header li
{
   ...
}

但是标签组件使用此样式表:

.tabset-style[_ngcontent-c13]   ul.tabset-header[_ngcontent-c13] li[_ngcontent-c13] {
   ...
}

如何让sass导入使用与tabs组件使用的css后缀相同的css后缀?

感谢

1 个答案:

答案 0 :(得分:0)

到目前为止,禁用封装可以解决问题

ViewEncapsulation:None

但问题在于,每当你想要自定义样式时,你就别无选择,只能摆脱封装

如果有人知道的更好......我都是耳朵