未捕获的ReferenceError:未在HTMLDivElement.onclick中定义openForm

时间:2017-12-01 20:40:27

标签: angular typescript button onclick

当我点击它时出现此错误,我不知道代码有什么问题,我使用TS和Angular,我没有语法错误,就在我运行的时候它在控制台上显示它" Uncaught ReferenceError:未在HTMLDivElement.onclick"

定义openForm



sieve = [True,True,True]
for x,y in enumerate(sieve):
   print(x,y)

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.scss']
})
export class HomeComponent implements OnInit {


  constructor() { }

  ngOnInit() {
  }


  }
const button = document.getElementById('mainButton');

      const openForm = function() {
      button.className = 'active';
    };

    this.checkInput = function(input) {
      if (input.value.length > 0) {
        input.className = 'active';
      } else {
        input.className = '';
      }
    };

    const closeForm = function() {
      button.className = '';
    };

    document.addEventListener('keyup', function(e) {
      if (e.keyCode === 27 || e.keyCode === 13) {
        closeForm();
      }
    });




0 个答案:

没有答案