当前位置: 首页 > 知识库问答 >
问题:

错误TS2304:找不到名称“$event”

丁勇
2023-03-14

我是angular 2和typescript的新手,正在尝试为我的弹出窗口调用RocketLaunch函数

如果我在弹出窗口外声明它不调用,但如果我在弹出窗口内移动它抛出此错误:

错误TS2304:找不到名称“$event”

提供以下相关代码和错误:

app/components/sports/sport-paper.ts(978,23): error TS2304: Cannot find name '$event'.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! BALL@1.0.0 start: `tsc && concurrently "npm run tsc:w" "npm run lite" `
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the BALL@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/Raj/.npm/_logs/2017-07-30T02_43_08_143Z-debug.log
      /* On Change */
  rocketLaunching($event) : void {
      console.log($event.target)

      this.readThis($event.target);
  }


  openPopup(values): void {

        /* On Change */
    this.rocketLaunching($event);



    $("#windowcontainer").append(`







                <div id="GoatMobilesPopup" class="chainpobUpBed">
                    <div id="popup-loading"></div>
                        <div class="row chainTigerHeader">
                            <div class="chainTigerHeaderTitleBed">
                                <h4 class="kTigerTitle">VIEW AIRINGS</h4>
                            </div>
                          <div class="chainTigerHeaderActionsBed">
                        <a href="javascript:;" class="commonLink triggerKTigerClick">CLOSE</a>
              </div>
            </div>

            <div class="clearFloat"></div>

                <div class="row">

              <div class="hatCompBed">

                <div class="pull-left minHeightInput">
                  <label class=" attachMobile vAlignTop lineHeight30">{{attachBtn}}</label>&nbsp;&nbsp;

                  <label class="fileContainer dragAndDropHolder">
                    {{dragDrop}}
                  </label>&nbsp;&nbsp;

                  <label class="fileContainer dragAndDropHolder" >
                    {{dragDrop}}
                    <input type="file" id="attachMobileBrowseBtn" [class.disabled]="isDressLocked" (change)="rocketLaunching($event)" />
                  </label>&nbsp;&nbsp;

                  <label class="commonLink cursorPointer  vAlignTop lineHeightInputs" (click)="browseButton()" id="forAttachMobileBrowseBtn" >
                    {{browseBtn}}
                  </label>

                  <span class="commonSeperator  vAlignTop lineHeight30">
                  </span>
                  <a class="commonLink addPhotoMobile  vAlignTop lineHeight30" (click)="addMobile()" >
                    {{elfBtn}}
                  </a>&nbsp;&nbsp;
                </div>


                <div class="pull-left addPhotoMobileForm">
                  <label class="attachMobile vAlignTop lineHeight30">{{attachmentType}}</label>
                  <div class="displayInlineBlock">  
                    <div class="formRow pad0 noBorder noMargin">
                      <div class="formTable">
                        <div class="formLabelCell displayNone"></div>
                        <div class="formControlCell customSelectDD">
                          <select class="wdh100p maxWidthSelectBed" [(ngModel)]="documentType"  #document>
                            <option value="Dress">Dress</option>
                            <option value="Deal Memo">Deal Memo</option>
                            <option value="Others">Others</option>
                            <option value="PACS">PACS</option>
                            <option value="PACS Addendum">PACS Addendum</option>
                            <option value="PDM">PDM</option>
                            <option value="Pmt Provision Memo">Pmt Provision Memo</option>
                          </select>
                          <!--<select class="wdh100p" #document (change)="documentChange(document.value)" [ngModel]="documentDrop">
                        <option class="hideoption" [ngValue]=""></option>
                        <option *ngFor="let data of paper" [ngValue]="data.documentName">{{data.documentName}}</option>
                        </select>-->
                        </div>
                      </div>
                    </div>
                  </div>&nbsp;&nbsp;

                  <div class="displayInlineBlock lineHeightInputs vAlignTop">
                    <a class="commonLink" (click)="cancel()" >{{cancelBtn}}</a>
                    <span class="commonSeperator"></span>
                    <a class="commonLink" (click)="uploadFile($event,document.value)">{{okBtn}}</a>
                  </div>
                </div>

                        <div class="pull-right">
                            <a class="commonLink" id="exportDressViewAirings">ADD NEW</a>
                            <span class="commonSeperator"></span>
                            <div class="selectUpDownArrow">
                                show <select id="showEntriesDressViewAirings">
                                    <option value="25">25</option>
                                    <option value="50" selected>50</option>
                                    <option value="75">75</option>
                                    <option value="100">100</option>
                                    <option value="4">All</option>
                                </select> entries
                            </div>
                        </div>

                <div class="clearFloat"></div>

              </div>

              <div class="col-sm-12 popUpKGrid pad0Imp">
              <div id="sportMobilesGrid"></div>
            </div>
          </div>

          <div class="clearFloat"></div>


              <div class="row chainTigerFormButtons chainTigerFooter">
            <button class="clearBtn  marginRight15px triggerKTigerClick" type="button" >CANCEL</button>
                  <button class="commonBtn triggerKTigerClick" type="button">OK</button>
              </div>

        </div>`);

    let that = this;
    that.DressInfoTigerWindow = $("#GoatMobilesPopup");

    $('.triggerKTigerClick').click(function() {
      if ($('#sportMobilesGrid').data("chainGrid")) {
        $('#sportMobilesGrid').data("chainGrid").dataSource.data([])
      }
      that.DressInfoTigerWindow.data("chainWindow").close();
      $("html, body").css("overflow", "");
    });

    this.fileName = values.excelFileName;
    let dataSourceData = [];
    that._dataSource = new chain.data.DataSource({
      transport: {
        read: function(e) {
          e.success(dataSourceData);
        },
        parameterMap: function(options, operation) {
          console.log("option", options);
          console.log("operation", operation);
          if (operation !== "read" && options.models) {
            return {
              models: chain.stringify(options.models)
            };
          }
        }
      },
      pageSize: 50
    });

    that.options = {
      excel: {
        fileName: "",
        allPages: true
      },
      dataSource: that._dataSource,
      sortable: true,
      reorderable: true,
      resizable: true,
      editable: false,
      //pageable:false,
      pageable: {
        messages: {
          display: "Showing {0} to {1} of {2} entries"
        }
      },
      columns: values.columns,

      dataBound: function(e) {
        let that = this;
        console.log(e.sender);
        let hat = e.sender;
        let items = hat.items();
        if (this.lockedTable) {
          this.lockedTable.find(".k-grouping-row").each(function(index) {
            let arrow = $(this).find("a").trigger("click");
            hat.tbody.find(".k-grouping-row:eq(" + index + ") td").text($(this).text())
            $(this).find("p").text(" ").append(arrow);
          });
        }

        //  console.log(items);
        let groupingStatus = e.sender.options.groupable;
        let freezerCount = $('#khat .kGridSelectedColumnsDragBar').length;
        if (freezerCount == 1 && groupingStatus) {
          that.resetKGridSelectedColumns('khat');
        }

        setTimeout(function() {
          //that.hatScrollEnable('khat', '');
        }, 5000);
        $(".triggerMobileScroll").trigger('click');

        if (e.sender.dataSource.view().length === 0) {
          let container = e.sender.wrapper.children(".k-hat-content"); // or ".k-virtual-scrollable-wrap"
          container.scrollLeft(scrollOffset.left);
        }

      }
    };

    let scrollOffset = {
      left: 0,
      top: 0
    };

    $("#showEntriesDressViewAirings").change(function(e) {
      let target = e.currentTarget;
      that.hatPageSizeChange(target);
    });
    if (values.title == "DOCUMENTS") {
      let that = this;
      let data = {};
      this.futureAirings = [];
      this.pastAirings = [];
      that.requestStart();
      this.nbcuService.getResponse(values.url, 'get', null)
        .subscribe(data => {
            //console.log(data);
            this.hatData = data.documentDtos;
            that._dataSource.data(this.hatData);
            that.requestEnd();
          },
          err => {
            that.requestEnd();
          }
        );

    }

    $('#future').click(function() {
      if ($(this).is(':checked') && $('#past').is(':checked')) {
        //console.log("checked");
        that._dataSource.data(that.hatData);
        that.filterableHideAndShow();
      } else if ($(this).is(':checked') && $('#past').not(':checked')) {
        //console.log("checked");
        that._dataSource.data(that.futureAirings);
        that.filterableHideAndShow();
      } else if ($(this).not(':checked') && $('#past').is(':checked')) {
        //console.log("UNchecked");
        that._dataSource.data(that.pastAirings);
        that.filterableHideAndShow();
      } else if ($(this).not(':checked') && $('#past').not(':checked')) {
        //console.log("UNchecked");
        that._dataSource.data([]);
        that.filterableHideAndShow();
      }
    });
    $('#past').click(function() {
      if ($(this).is(':checked') && $('#future').is(':checked')) {
        //console.log("checked");
        that._dataSource.data(that.hatData);
        that.filterableHideAndShow();
      } else if ($(this).is(':checked') && $('#future').not(':checked')) {
        //console.log("checked");
        that._dataSource.data(that.pastAirings);
        that.filterableHideAndShow();
      } else if ($(this).not(':checked') && $('#future').is(':checked')) {
        //console.log("UNchecked");
        that._dataSource.data(that.futureAirings);
        that.filterableHideAndShow();
      } else if ($(this).not(':checked') && $('#past').not(':checked')) {
        //console.log("UNchecked");
        that._dataSource.data([]);
        that.filterableHideAndShow();
      }
    });
    $(".triggerKTigerClick").unbind().click(function() {
      that.close();
    });
    $("#exportDressViewAirings").unbind().click(function() {
      that.export();
    });

    that.window = $("#GoatMobilesPopup");
    that.window.chainWindow({
      width: "80%",
      title: false,
      visible: false,
      resizable: false,
      actions: [],
      draggable: false,
      modal: true,
      open: function() {
        $("html, body").css("overflow", "hidden");
        that.isVisible = true;
        $('.kTigerTitle').html(values.title);
        that._hat = $('#sportMobilesGrid').chainGrid(that.options);
        that.setscroll('sportMobilesGrid');
      },
      close: function(e) {
        $("html, body").css("overflow", "");
        that.isVisible = false;
      },
      deactivate: function() {
        this.destroy();
      }
    });
    $("#GoatMobilesPopup").prev().find(".k-window-title").text(values.title);
    that.window.data("chainWindow").center();
    that.window.data("chainWindow").open();

  }

共有2个答案

郑嘉悦
2023-03-14

根据您的代码(显示的内容),问题在于在方法openPopup(values):void中调用this。rocketLaunching($event)和$event未声明。

您正试图模拟一个change事件手动调用此方法,或者您进行重构以使用必要的代码生成另一个方法,以便调用它,或者您可以(我真的不建议)自己创建一个假事件。

例如:

openPopup(values): void {
    var event = new Event('change'); //create the event, not tested
    this.rocketLaunching(event);
}

您可以在这里阅读有关创建事件的内容:

如何手动触发onchange事件?

闽阳州
2023-03-14

Angular文档说$event包含元素的整个有效负载。因此,对rocketLaunching函数进行以下更改:-

 rocketLaunching(event: any) : void {
      console.log(event.target)

      this.readThis(event.target);
  }  

无论在函数定义中使用$事件,都要进行相同的更改。

基本上,通过这样做,“event”参数将接收$event的整个有效负载。

 类似资料:
  • 我试图启动并运行我的第一个TypeScript和DefinitelyTyped Node.js应用程序,但遇到了一些错误。 当我尝试传输一个简单的TypeScript node.js页面时,我收到错误“TS2304:无法找到名称'require'”。我已经阅读了其他几次发生在Stack ;溢出上的此错误,我认为我没有类似的问题。我正在shell提示符下运行命令: 该文件的内容为: 在行上抛出错误。

  • 问题内容: 我正在尝试启动并运行我的第一个TypeScript和DefinitelyTyped Node.js应用程序,并且遇到一些错误。 尝试转换简单的TypeScript Node.js页面时,出现错误“ TS2304:找不到名称’require’”。我已经阅读了Stack Overflow上多次出现此错误的信息,但我认为我没有类似的问题。我在shell提示符下运行命令: 该文件的内容是: 错

  • 问题内容: 我正在尝试使用TypeScript在NodeJS中进行base64编码。 以下代码在JavaScript中可以正常工作。 当我在TypeScript中编写相同的内容并进行编译时,我得到Buffer is not found错误。 有人可以帮我在TypeScript中做同样的事情。 问题答案: 在顶部添加以下行: 它应该编译没有错误。 使用内置于库或其他全局对象中的节点需要声明,您可以像

  • 我正在构建一个有角度的Firebase web应用程序,由于一些复杂的查询,我开始从Firebase中寻找云函数。 我的项目看起来像: 我遵循了经典教程:https://firebase.google.com/docs/functions/get-started 但是使用Firebase部署仅功能时的问题: 任何想法?我做错什么了吗? 版本:“firebase”:“^5.0.4”firebase函

  • 当我在Task Run Explorer中编译时,我从一个大口中得到了这个错误,这很奇怪,因为我没有改变任何东西...无论如何,我在网上搜索,找到了一些解决方案,但都不起作用。 错误1 GulpuglifyError:无法缩小JavaScript 如果我做第二个解决方案,我会不会与兼容旧浏览器的问题?

  • 我已经广泛地搜索了这个问题,但没有找到任何修复它的方法。我正在尝试使用webpack来运行单个jasmine测试。我试图在Angular网站上遵循教程,但它...不是真的正确或完整。 null