当模板中的div改变大小时,执行某些操作的最佳方法是什么?调整窗口大小时,div的大小会更改.使用Rxjs Observable/subscribe还是其他方式?
模板:
<div #eMainFrame class="main-frame">
...
</div>
Run Code Online (Sandbox Code Playgroud)
零件:
@Component({
selector: 'app-box',
templateUrl: './box.component.html',
styleUrls: ['./box.component.css']
})
export class BoxComponent implements OnInit {
@ViewChild('eMainFrame') eMainFrame : ElementRef;
constructor(){}
ngOnInit(){
// This shows the elements current size
console.log(this.eMainFrame.nativeElement.offsetWidth);
}
}
Run Code Online (Sandbox Code Playgroud)
更新的组件(此示例检测窗口大小何时更改)
constructor(ngZone: NgZone) {
window.onresize = (e) => {
ngZone.run(() => {
clearTimeout(this.timerWindowResize);
this.timerWindowResize = setTimeout(this._calculateDivSize, 100);
});
}
}
_calculateDivSize(){
console.log(this.eMainFrame.nativeElement.offsetWidth);
}
Run Code Online (Sandbox Code Playgroud)
但这给了我一个错误:
EXCEPTION:无法读取未定义的属性"nativeElement"
我有一个值为"2014-10-10"的dateColumn和值为"10:10:44"的startTimeColumn.如何从dateColumn位于'startDate'和'endDate'之间的表中选择所有内容,并且startTimeColumn在'startDate'上大于或等于'startTime'?
这就是我的意思:(我知道这不起作用,但只是为了表明我的意思)
SELECT * FROM table1 WHERE dateColumn BETWEEN 'startDate' AND 'endDate' AND IF TRUE(
IF(dataColumn == 'startDate')
THEN IF(startTimeColumn >= 'startTime')
RETURN TRUE
ELSE
RETURN FALSE
ELSE
RETURN TRUE
);
Run Code Online (Sandbox Code Playgroud)
我正在使用MySQL,我不能使用SQL函数.
有没有一种简单的方法可以按数字对数组进行排序?如果一个数字具有相同的计数,则将最高数字放在第一位.
[2,8,2,6,1,8,2,6,6]
to
[6,6,6,2,2,2,8,8,1]
Run Code Online (Sandbox Code Playgroud)