[英]Is there any way to use closure in angular 4
我想在函數內部創建函數以在Angular 4中關閉。
當我嘗試執行以下操作時,出現“找不到名稱innerFn”錯誤
outerFn(){
let a = "hello";
innerFn(){
console.log(a);
}
}
有人可以幫我嗎?
您應該使用function
關鍵字:
outerFn(){
let a = "hello";
var that = this; // use that to access the component
function innerFn(){
console.log(a);
}
innerFn(); // will log a
}
警告:如果您嘗試在此函數中使用this
功能,由於關閉,它將不會引用您的組件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.