- 我是新來的typescript和angular js。
- 我試圖在我的代碼中包含另一個組件代碼。
- 這是baby.js代碼到我的代碼
- 但我得到一個錯誤。 TypeError:無法讀取未定義的屬性'tigerStart'
- 可以告訴我如何解決它。
- 提供下面
TypeError: Cannot read property 'tigerStart' of undefined
at init.open (pen-pencil.ts:1270)
at init.trigger (kendo.all.min.js:25)
at init.open (kendo.all.min.js:45)
at Penguin.openPopup (pen-pencil.ts:1286)
at penguin.pencilClicked (headset.ts:689)
at _View_penguin4._handle_click_45_0 (penguin.ngfactory.js:4087)
at eval (core.umd.js:9698)
at eval (platform-browser.umd.js:1877)
at eval (platform-browser.umd.js:1990)
at ZoneDelegate.invoke (zone.js:203)
我的代碼包括tigerStart方法成整體js代碼typeError:無法讀取undefined屬性'tigerStart'
@ViewChild(體育)公共天空:運動;
that.window = $("#PenguinPopup");
that.window.kendoWindow({
width: "60%",
title: false,
visible: false,
resizable: false,
actions: [],
draggable: false,
modal: true,
open: function() {
$("html, body").css("overflow", "hidden");
that.isVisible = true;
$('.kPopUpTitle').html(values.title);
this.sky.tigerStart();
包括魚類組件到我的HTML
<div class="clearFloat"></div>
<ul class="kendu-custom-contextmenu" id="context-menuFinancialSearch">
<li class="kPopUpBtnTriple">View Details</li>
<li class="kPopUpBtnTriple">Manage Documents</li>
</ul>
<financeLeftSlider (savedSearchData)='getSaveEvent($event)'></financeLeftSlider>
<Fish></Fish>
<Penguin (documentCount)='getDocumentEvent($event)'></Penguin>
<sports></sports>
<div class="searchNameRequiredPopup">
<div class="pipepobUpBox pipeWindow kPopupConfirmationBox">
<div class="row pipePopUpGridCollection pipePopUpContent lineHeightInputs">
<div class="pipeContent">Please enter the search name.</div>
</div>
<div class="clearFloat"></div>
<div class="row pipePopUpFooter textAligncenterImp">
<!-- <button class="commonBtn" type="button" id ="deleteDocumentYes">Yes</button> -->
<button class="clearBtn" type="button" id="searchNameRequiredBtn">Ok</button>
</div>
<div class="clearFloat"></div>
</div>
</div>
baby.html
<div id="baby"></div>
<div id="baby1"></div>
baby.js
@Component({
moduleId: module.id,
selector: 'sports',
templateUrl: 'sports.html'
})
export class Star {
tigerStart(): void {
kendo.ui.sky($("#baby"), true);
}
tigerEnd(): void {
kendo.ui.sky($("#baby"), false);
}
tigerStart1(): void {
kendo.ui.sky($("#baby1"), true);
}
tigerEnd1(): void {
kendo.ui.sky($("#baby1"), false);
}
}
- 當我打印這張圖時,我沒有看到天空,所以我閱讀了中型表格,並試圖用胖箭頭進行綁定,但仍然無法完成它。
- 在視圖中,我正在使用運動的孩子
- 你能告訴我如何解決它。
- 以便爲今後這將有助於
https://medium.com/@thejasonfile/es5-functions-vs-es6-fat-arrow-functions-864033baa1a
@ViewChild(sports) public sky: sports;
**- tried with fat arrow**
open:() => {
**- tried with bind**
this.sky.tigerStart().bind(this);
感謝您的回覆。 - 當我打印這張照片時,我沒有看到天空,所以我閱讀了介質表格,並嘗試着用箭頭和箭頭進行綁定,但仍然無法完成。 - 在視圖中,我正在使用運動 - 你能告訴我如何解決它。 - 以便將來有幫助 –
https://medium.com/@thejasonfile/es5-functions-vs-es6-fat-arrow-functions-864033baa1a @ViewChild(sports)public sky:sports; open:()=> { this.sky.tigerStart()。綁定(本); –
我讀過你引用的文章。有趣。我不知道ES6「胖箭頭」以這種方式保留了「這個」範圍。但無論如何,你所做的改變已經讓事情變得糟糕。你調用綁定,但在那一行,現在已經太晚了,因爲你已經在函數中。你沒有真正給我足夠的信息來解決你的問題。我只能猜測。我會嘗試更新我的答案,您可以嘗試查看它是否適合您。 – ultramoka