Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何将“样式显示:无”设置为角度动画前后的查询?_Angular_Angular Animations - Fatal编程技术网

Angular 如何将“样式显示:无”设置为角度动画前后的查询?

Angular 如何将“样式显示:无”设置为角度动画前后的查询?,angular,angular-animations,Angular,Angular Animations,我有一个大的有角度的材料形式分裂成更小的和平,我想动画之间的垫卡,我把控制。我使用*ngIf来显示和隐藏卡片,但是初始化内容会使动画变得粗糙,所以我想使用display none来代替它。我不知道如何在其他步骤中隐藏卡 这是我的简化组件: @Component({ selector: "material-app", templateUrl: "app.component.html", styleUrls: ["app.component.scss"], animations: [

我有一个大的有角度的材料形式分裂成更小的和平,我想动画之间的垫卡,我把控制。我使用*ngIf来显示和隐藏卡片,但是初始化内容会使动画变得粗糙,所以我想使用display none来代替它。我不知道如何在其他步骤中隐藏卡

这是我的简化组件:

@Component({
  selector: "material-app",
  templateUrl: "app.component.html",
  styleUrls: ["app.component.scss"],
  animations: [
    trigger("state", [
      //state("state2", style({ display: "none" })),
      transition("state1 => state2", [
        group([
          query('#card2', [style({display: 'none', opacity: 0})]),
          query("#card1", [
            animate(
              `${AnimationDurations.EXITING} ${
                AnimationCurves.ACCELERATION_CURVE
              }`,
              style({ transform: "translateY(56px)", opacity: 0, display: 'none' })
            )
          ])
        ]),
        query("#card2", [
          style({ opacity: 0, display: '*' }),
          group([
            style({
              transform: "translateY(-56px)",
              opacity: 0
            }),
            animate(
              `${AnimationDurations.ENTERING} ${
                AnimationCurves.DECELERATION_CURVE
              }`,
              style("*")
            )
          ])
        ])
      ])
    ])
  ]
})
export class AppComponent {
  state = 'state1';
  reset() {
    setTimeout(()=> {
      this.state = 'state1'
    }, 500)
  }
}
这将是我的特马普拉特


国家1
国家2
卡1
卡2
状态===state1
时,我想隐藏
#card2
,反之亦然。动画工作正常,但前后两张卡都可见。


我的stackblitz示例:

如果我正确理解您,请尝试以下代码:


    <mat-card id="card1" [style.display]="state=='state1'?'block':'none'">Card 1</mat-card>
    <mat-card id="card2" [style.display]="state=='state2'?'block':'none'">Card 2</mat-card>


卡1
卡2

如果我正确理解您,请尝试以下代码:


    <mat-card id="card1" [style.display]="state=='state1'?'block':'none'">Card 1</mat-card>
    <mat-card id="card2" [style.display]="state=='state2'?'block':'none'">Card 2</mat-card>


卡1
卡2

这是我的解决方案,但在我的示例中,请尝试在您的项目中使用它

我对angular 7有这个问题

  animations: [
trigger('openClose', [
  // ...
  state('open', style({
    'height': '20px', 'width':'120px', 'opacity': '1'
  })),
  state('closed', style({
    'height': '0','width':'0', 'opacity': '0'
  })),
  transition('open => closed', [
    animate('1s')
  ]),
  transition('closed => open', [
    animate('0.5s')
  ]),
]),]
在组件中

  isOpen = true
  toggle() {
     this.isOpen = !this.isOpen;
  }
的确如此

      Click to toggle the animation : <button (click)="toggle()" style="cursor: pointer;" aria-label="Example delete icon">
    {{isOpen? 'Hide input' : 'Display input'}}
  </button>
  <input style="margin-left:10px" [@openClose]="isOpen ? 'open' : 'closed'" class="open-close-container" placeholder="" />
单击以切换动画:
{{isOpen?'Hide input':'Display input'}
这是演示


这是我的解决方案,但在我的示例中,请尝试在您的项目中使用它

我对angular 7有这个问题

  animations: [
trigger('openClose', [
  // ...
  state('open', style({
    'height': '20px', 'width':'120px', 'opacity': '1'
  })),
  state('closed', style({
    'height': '0','width':'0', 'opacity': '0'
  })),
  transition('open => closed', [
    animate('1s')
  ]),
  transition('closed => open', [
    animate('0.5s')
  ]),
]),]
在组件中

  isOpen = true
  toggle() {
     this.isOpen = !this.isOpen;
  }
的确如此

      Click to toggle the animation : <button (click)="toggle()" style="cursor: pointer;" aria-label="Example delete icon">
    {{isOpen? 'Hide input' : 'Display input'}}
  </button>
  <input style="margin-left:10px" [@openClose]="isOpen ? 'open' : 'closed'" class="open-close-container" placeholder="" />
单击以切换动画:
{{isOpen?'Hide input':'Display input'}
这是演示


是的,我也尝试过,但这会立即隐藏卡,而不是在过渡后@罗马·鲁齐切亚,我也试过,但这会立即隐藏卡德,而不是在过渡后@罗马鲁齐奇