角简单ngIf如果倒置?

时间:2019-06-29 15:42:47

标签: html angular angular-ng-if

自制NavBar。环境包含具有定义如下的下拉元素的列表:

      {
      title: 'Overview', isDropped: false, Links: [
        {linkTitle: 'What is Hunter', linkRoute: '/whatishunter'},
        {linkTitle: 'What is a Hard Problem', linkRoute: '/hardproblem'},
        {linkTitle: 'Real World Applications', linkRoute: '/realapps'},
        {linkTitle: 'Using Hunter', linkRoute: '/usingHunter'}
        ]
      },

导航栏html会为该导航栏该部分中的每个下拉列表循环(ngFor);添加的leftdropdown被删除以显示正在发生的事情:

<div class="positionLeft" [ngStyle]="{'z-index': '2', 'height': '50px'}">
<div *ngFor="let leftdropdown of barContents.leftMenus">
  <app-navdropdown [title]="[leftdropdown.title]" [isDropped]="[leftdropdown.isDropped]"
                   [links]="[leftdropdown.links]"></app-navdropdown>
          added leftdropdown isdropped = {{leftdropdown.isDropped}}
</div>

“ leftdropdown”元素来自上面的环境列表。 component.ts是:

enter image description here

它是简单的HTML(带有额外的诊断文本): enter image description here

因此,当应用程序运行时,我们看到的输出html为: enter image description here

在此处注意调试控制台: enter image description here

并且可以肯定的是,我可以手动将isDropped更改为true并显示“ if block”。 明显的错误是* ngIf正在反转isDropped表达式????

关于什么是误解或简单语法错误的任何线索?
感谢您的时间和建议。 查克(瑜伽士)

1 个答案:

答案 0 :(得分:0)

感谢各种评论;我终于意识到我对方括号的困惑是关于表达的左或右。在左侧使用(或不使用)方括号会更改右侧的评估方式。 (我认为它们需要应用到右侧-错误)。 在仔细(并反复)查看angular.io中的属性绑定文档之后,以上内容对我很清楚。
感谢所有添加注释的人。

相关问题