首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用渲染器(角7)绘制组件内部的<style>

用渲染器(角7)绘制组件内部的<style>
EN

Stack Overflow用户
提问于 2018-12-08 12:31:12
回答 1查看 800关注 0票数 0

我对渲染内部组件有问题。我希望从另一个组件发出数据并发送到另一个组件,但是问题是当我用元素创建Renderer2时,它有时是工作的,但有时不工作。在组件中呈现样式元素可能是个问题吗?

发布数据的toolbar.state.service.ts服务方法

代码语言:javascript
复制
private globalStyles = new BehaviorSubject<string>('');
formDesign(data: any) {
   this.globalStyles.next(data);
}

这里的aside.component.ts从反应性表单控件发出数据并发送到另一个组件。

代码语言:javascript
复制
// Height
    this.formGlobal.controls['height'].valueChanges
      .pipe(debounceTime(500))
      .pipe(distinctUntilChanged())
      .pipe(takeUntil(this.destroy$))
      .subscribe(height => {
        this.formGlobal.controls['height'].setValue(height);
        this.formGlobal.updateValueAndValidity();
        this.showDataCriteria = {
          width: this.formGlobal.controls['width'].value + 'px',
          height: height + 'px'
        };
        this.toolbarStatus.formDesign(this.showDataCriteria);
      });

builder.component.ts在这里,我从aside.component.ts那里得到数据,它收到了!

代码语言:javascript
复制
/**
   * Generate CSS
   */
  generateCss() {
    let basicStyles = ' ';
    let newStyle: HTMLElement;
    let style: HTMLElement = this.document.getElementById('custom-class');
    style
      ? (newStyle = style)
      : (newStyle = this.renderer.createElement('style'));

    this.renderer.setAttribute(newStyle, 'id', 'custom-class');
    let completeStyleFields = '';
    this.customStyle.global
      ? (basicStyles += `#${this.projectInfo.id} {${this.customStyle.global}}`)
      : (basicStyles += '');
    console.log(basicStyles);
    this.customStyle.sections.forEach(element => {
      completeStyleFields += `#${element.id} {${element.textProps}}`;
    });
    basicStyles += completeStyleFields;
    const text = (this.document.textContent = basicStyles);
    newStyle.innerText = text;
    this.renderer.appendChild(this.dndComponent.nativeElement, newStyle);
  }

主要问题是在创建了样式元素之后,我看到DOM中的元素,样式不接受!有时接受,有时不接受。我该怎么办?如何操纵重新加载页面可能注入组件和样式元素?总之,我看到#4152ae54-8a9d-49d5-a33d-62dfbbd35890 {高度:600‘m;宽度:812’m;}但样式不被元素接受!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-10 17:12:37

如果第一个数字字母(#4152ae54-8a9d-49d5-a33d-62dfbbd35890),CSS无法呈现。这是因为尽管HTML5很高兴ID以数字开头,但CSS却不是。CSS只是不允许选择器以数字开头。规范的相关部分规定。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53682554

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档