1.当我想通过.ts文件控制前台样式时:
error TS2339: Property 'style' does not exist on type 'Element'.
解决方案: 设定变量类型为any
var dgbc:any =document.getElementsByClassName('div-bg');
dgbc[0].style.backgroundColor='#D8D8D8';
2.同一页面进行点击切换时,ngfor进行页面渲染,并且通过ts设定前台样式时,有的样式失效
(1):打印dgbc的长度时,显示长度为上一阶
点送签,显示的是待签核页面的数据长度。
<div class="div-out" *ngFor="let item of items let i=index">
<div class="div-bg" id="{{i}}" (click)="isShow(i)" style="background-color: #D8D8D8;">
<span class="title-nav">
<div style="float:left">{{item}}</div>
<div class="num">{{subSum[i]}}</div>
</span>
</div>
<div [hidden]="flag!=i">
<st #st [data]="firstData" [columns]="firstColumns"></st>
</div>
</div>
解决方案:::监听ngfor:当ngfor执行完后再执行页面渲染
setTimeout(() => {
var dgbc:any =document.getElementsByClassName('div-bg');
if(dgbc.length== this.subSum.length)
this.isShow(0);
return;
}, 1);
3.STComponent Property 'st' has no initializer and is not definitely assigned
意思是STComponent属性’st’没有初始化器,也没有明确赋值
解决方案:
Just go to tsconfig.json and set
"strictPropertyInitialization": false
to get rid of the compilation error. --以消除编译错误。
Otherwise you need to initialize all your variables which is a little bit annoying–否则你需要初始化所有的变量这有点烦人