Ionic Error v.context.$implicit is undefined

て烟熏妆下的殇ゞ 提交于 2019-12-02 04:58:15

问题


I have the error in my code. The error says like this: v.context.$implicit is undefined

The problem is, sometimes it error, and sometimes it doesn’t… Can somebody explain why it happen…

This my html code:

<ng-container *ngFor="let time of item.timeInfo | keys" >
    <ion-row *ngIf="time == thisDay"> 
      <ion-col col-3 no-padding>
        <ng-container *ngIf="checkTime(); else closeButton">
          <button small ion-button block color="secondary" outline> OPEN </button>
        </ng-container>
        <ng-template #closeButton>
          <button small ion-button block color="danger" outline>Close </button>
        </ng-template>
      </ion-col>
      <ion-col col-9 >
        {{ item.timeInfo[thisDay].open }} - {{ item.timeInfo[thisDay].close }}
      </ion-col>
    </ion-row>
  </ng-container>

Here my json code:

"item":{
   "timeInfo": {
            "Sat": {
                "open": "11:00",
                "close": "21:00"
            },
            "Sun": {
                "open": "9:00",
                "close": "21:30"
            },
            "Mon": {
                "open": "11:00",
                "close": "22:30"
            },
            "Tue": {
                "open": "12:00",
                "close": "22:00"
            },
            "Web": {
                "open": "12:00",
                "close": "22:30"
            },
            "Thu": {
                "open": "9:30",
                "close": "22:30"
            },
            "Fri": {
                "open": "12:30",
                "close": "22:00"
            }
        },
 };

And here my version:

@ionic/cli-utils  : 1.15.2
ionic (Ionic CLI) : 3.15.2

local packages:
@ionic/app-scripts : 3.0.0
Ionic Framework    : ionic-angular 3.7.1

System:
Node : v6.11.2
npm  : 5.4.2
OS   : Windows 8.1

Misc:
backend : pro

Can somebody help me?? Tyvm


回答1:


i can't really help if i don't see you're TS code. The same problem occured to me and my mistake was to try to insert a new data in an array like result[i] = data[i] and not like result.push(data[i]) which is actually correct. Hope it helps !




回答2:


Most of the time, context.$implicit refer in the template to a variable created with a "let" (like "let time of item.info").

The rest of the error ("is undefined") is the classic javascript error message for trying to use a undefined value like an object.

In your case, it probably happen when the variable thisDay is not one of the key of timeinfo. checking the exact line of the error will probably help finding the error in the html.



来源:https://stackoverflow.com/questions/47008316/ionic-error-v-context-implicit-is-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!