从Angular 2组件调用函数

时间:2018-05-03 19:32:21

标签: javascript angular

我有一个函数,它接受一组数字并返回一个计算值。当我尝试从ngAfterViewInit

调用它时

当我这样做时,我得到一个未定义的错误。

如何在角度2中创建可以从ngAfterViewInit触发的函数?

ngOnInit()

之后
  ngAfterViewInit(){
    this.gridW = document.getElementById('grid').offsetWidth;

    console.log(getColWidth(10,8,800));
     
  }

  getColWidth(gutW,colN,gridW) {
    let gutWTotal = gutW*(colN-1);
    let gridWResult = gridW - gutWTotal;
    let colW = gridWResult/colN;

    return Math.floor(colW);
  }

错误:ERROR ReferenceError: getColWidth is not defined

0 个答案:

没有答案
相关问题