I have below part of code:
if (this.holdReasonList.length == 1 || this.holdReasonList == undefined || this.holdReasonList.length == 0) {
return this._cciDataService.getHoldReasonDropList()
.pipe(takeUntil(this.unsubscribe))
.subscribe((res) => {
if (res.Success) {
let defaultList = [];
res.Data.forEach((reason: string) => {
defaultList.push(reason.trim());
})
I always got undefined error of defaultList
after I called this line:
let defaultList = [];
I do not understand why defaultList
is not defined since I clearly declared it.
Thanks for the help in advance!
UPDATE:
Thanks for the advice! Since I tried put the let defaultList=[]
outiside the whole piece of the subscribe block, it works now.
But the reason is not clear. I set the break point and type let defaultList = []
in the console and it also returns undefined. Please see below screenshot:
I think I do not need to even think of where the defaultList
to be used, the defualtList
is undefined right after the declaration. I do not have any chance to even use its value....
Ok. When I debug on Chrome devTool, the variable is defined....The issue was that I was debugging by using VSCode.
Be aware that let
keyword will cause undefined variable on VSCode debugger.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.