获取co.myFunction不是函数错误

时间:2019-01-22 17:03:04

标签: angular

我在执行angularjs代码时遇到错误 HTML代码:

<tbody>
              <tr>
              <td class=" ">1<sup>st</sup>
                <div class="box draggable" 
                      appDraggable
                      (draggStart)="ondraggStart()">Delete1</div></td>
                <td class=""><button class="btn " data-toggle="modal" data-target="#EditClass">Edit</button>
                <button class="btn  ">Delete</button></td>
              </tr>
              <tr>
              <td class=" ">2<sup>nd</sup></td>
                <td class=""><button class="btn " data-toggle="modal" data-target="#EditClass">Edit</button>
                <button class="btn  ">Delete</button></td>
              </tr>
              <tr>
              <td class=" ">3<sup>rd</sup></td>
                <td class=""><button class="btn " data-toggle="modal" data-target="#EditClass">Edit</button>
                <button class="btn  ">Delete</button></td>
              </tr>

            </tbody>

app.component.ts文件代码:

import { Component} from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
ondraggStart = function(){
console.log("got drag start");
}
}

下面是我的 draggble.directive.ts代码:

import { Directive, HostBinding, HostListener, Output, EventEmitter } from 
'@angular/core';
@Directive({
selector: '[appDraggable]'})
export class DraggableDirective {
@HostBinding('class.draggable') draggable=true;
@Output() draggStart =new EventEmitter<PointerEvent>();
private dragging =false;
@HostListener('pointerdown',['$event']) onpointerdown(event:PointerEvent): 
void{
  this.dragging=true;
  this.draggStart.emit(event);
}
}

执行后,我遇到以下错误:

ERROR TypeError: _co.ondraggStart is not a function
at Object.eval [as handleEvent] (AddClassComponent.html:24)
at handleEvent (core.js:10251)

请让我知道是否有人在角度投影中遇到此错误

1 个答案:

答案 0 :(得分:0)

通过加载引导程序库,我的问题已解决。