您好我建立了关于威士忌:)的网站,我需要从查询中使用一些代码(按类.calcheight计算元素的高度)。如何重写这段代码?我的意思是如何创建函数(返回数字的typescript)以及如何选择元素因为我不想使用jQuery?
Angular2:
import { Component } from '@angular/core';
import { WhiskyService } from './whisky.service';
import { Whisky } from './whisky.interface';
@Component({
selector: 'whisky-grid',
host: {
class: 'ui grid'
},
templateUrl: 'app/whisky.component.html',
providers: [WhiskyService]
})
export class AppComponent {
whiskyList: Array<Whisky>;
constructor(private _whiskyService: WhiskyService) { }
getWhisky() {
this.whiskyList = this._whiskyService.getWhisky();
}
ngOnInit() {
this.getWhisky();
}
}
和jquery:
var CalcHeight = function(){
function getMaxHeight(el){
var element = $(el);
var height = 0;
element.each(function() {
if(height < $(this).height()) {
height = $(this).height();
}
});
return height;
}
function setHeight(el, value){
var element = $(el);
element.each(function() {
$(this).height(value);
});
}
function setParam(el, param, block){
$(block).css(param, getMaxHeight(el));
}
function render(el) {
setHeight(el, getMaxHeight(el));
}
return {
getMaxHeight : getMaxHeight,
setParam : setParam,
init : function (el){
render(el);
}
}
}();
CalcHeight.init('.calcheight');