简体   繁体   English

角“未定义标识符'todos'。”

[英]Angular “Identifier 'todos' is not defined.”

what could be the cause of this error 可能是此错误的原因

"Identifier 'todos' is not defined. The component declaration, template variable declarations, element references do “未定义标识符'todos'。组件声明,模板变量声明,元素引用

I've been trying to run this in ionic4 linking it to firebase and this error is popping up on the various lines (12,36) and (9,41). 我一直试图在ionic4中将其链接到firebase上运行,并且此错误在各种行(12,36)和(9,41)上弹出。

<ion-header>
          <ion-toolbar color="primary">
            <ion-title>
              Ionic FireStore
            </ion-title>
          </ion-toolbar>
        </ion-header>

        <ion-content>

          <ion-list>
            <ng-container *ngIf="!todos || todos.length == 0">
              <div *ngFor="let n of [0,1,2]" padding>
                <p>
                  <ion-skeleton-text class="fake-skeleton"></ion-skeleton-text>
                </p>
              </div>
            </ng-container>
          <ion-item-sliding *ngFor="let item of todos">
            <ion-item lines="inset" button[routeLink]=" ['/details, item.id'] ">
              <ion-label>
                {{item.task}
              <p>{{ item.createdAt | date:'short'}} </p>
              </ion-label>
              <ion-note slot="end" color="primary"> {{ item.priority }} </ion-note>

            </ion-item>
            <ion-item-options side="end">
              <ion-icon name="checkmark" slot="end"></ion-icon>
            </ion-item-options>
          </ion-item-sliding>
          </ion-list>

          <ion-fab vertical="bottom" horizontal="end" slot="fixed">
            <ion-fab-button routerLink="/details" routerDirection="forward">
              <ion-icon name="add"></ion-icon>
            </ion-fab-button>

          </ion-fab>

    </ion-content>

'todos' is not defined. 未定义“待办事项”。

This is a Javascript error. 这是一个Javascript错误。 It says you have not defined the variable todos . 它说您尚未定义变量todos

You most likely have a component that contains the described HTML . 您最有可能具有包含描述的HTML组件

You could try the following... 您可以尝试以下...

...in component
todos;
constructor()...

or 要么

...in component
todos = [];
constructor()...

On a side note... 旁注...

Open your browser console and type: todos; 打开浏览器控制台,然后键入:todos;

You get back: "Uncaught ReferenceError: todos is not defined" 您回来:“ Uncaught ReferenceError:未定义todos”

Type: var todos; 类型:var todos;

You get back: "undefined" 您返回:“未定义”

See the difference? 看到不同? The "undefined" of the "defined" todos variable is referencing an undefined right-hand assignment; “已定义” todos变量的“未定义”引用了未定义的右侧分配; ie it has nothing defined attached to the defined todos . 也就是说,它与定义的待办事项无关。 It's a bit confusing. 这有点令人困惑。

All variables must be defined before they are used. 使用前必须先定义所有变量。 When you defined a variable in a javascript class we leave out the var/let and just declare it as in 当您在javascript类中定义变量时,我们忽略了var / let,只是将其声明为

class Todo {
  todos;

  constructor(){}
}

The todos variable is declared. 声明了todos变量。 The left hand assignment is todos, and the right hand side is default undefined since nothing was provided. 左手分配是待办事项,而右手默认是未定义的,因为未提供任何内容。 undefined points to the righthand side, not to the lefthand side. 未定义指向右侧,而不是左侧。 We must always provide a lefthand side assignment before using any variable. 在使用任何变量之前,我们必须始终提供左侧分配。

You are using "!todos || todos.length == 0" 您正在使用“!todos || todos.length == 0”

!todos means that there is a defined variable todos that has a falsey righthand side assignment of either: false, 0, "", null, NaN, or undefined. !todos表示存在一个已定义的变量todos,该变量的falsey右侧分配为false,0,“”,null,NaN或undefined。 Then you are using the BANG operator to flip the logic. 然后,您正在使用BANG运算符来翻转逻辑。 In any case, you must defined the variable todos in the proper scope. 无论如何,您必须在适当的范围内定义变量todos

I think you answered yourself here: 我想你在这里回答了自己:

<ng-container *ngIf="!todos || todos.length == 0">

That ng-container should not show if todos is undefined! 如果未定义待办事项,则该ng容器不应显示!

Now, outside that ng-container you have: 现在,在该ng容器之外,您具有:

<ion-item-sliding *ngFor="let item of todos">

You should add the code from the ng-container here too, so you would have something like this: 您也应该在这里添加ng-container中的代码,这样您将获得以下内容:

<ng-container *ngIf="!todos || todos.length == 0">
   <ion-item-sliding *ngFor="let item of todos">
</ng-container>

Then, that ion-item-sliding wouldn't show either if todos is undefined! 然后,如果待办事项未定义,也不会显示该离子项目滑动!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未定义标识符“标题”。 &#39;{}&#39; 不包含这样的成员 angular 8 - Identifier 'title' is not defined. '{}' does not contain such a member angular 8 已解决 Angular 标识符“标题”未定义。 'Movie[]' 不包含这样的成员 - Solved Angular Identifier 'title' is not defined. 'Movie[]' does not contain such a member 未定义标识符“ X”。 “ Y”不包含此类成员Angular - Identifier 'X' is not defined. 'Y' does not contain such a member Angular 未定义角度标识符“ playerType”。 &#39;&#39;不包含这样的成员 - Angular Identifier 'playerType' is not defined. '' does not contain such a member 未定义标识符“ ...”。 &#39;__type&#39;不包含这样的成员Angular FormArray - Identifier '…' is not defined. '__type' does not contain such a member Angular FormArray Angular:标识符“标题”未定义。 'never' 不包含这样的成员。 异常问题 - Angular: Identifier 'title' is not defined. 'never' does not contain such a member. Unusual problem 标头未定义。 在运行角度通用时 - Headers is not defined. When running angular universal 未定义标识符“X”。 'Y' 不包含这样的成员 - Identifier 'X' is not defined. 'Y' does not contain such a member 未定义标识符“长度”。 &#39;null&#39; 不包含这样的成员 ng(0) - Identifier 'length' is not defined. 'null' does not contain such a member ng(0) 未定义标识符“必需”。 &#39;__type&#39; 不包含这样的成员 - Identifier 'required' is not defined. '__type' does not contain such a member
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM