【问题标题】:Violation click handler took angular 5 and chrome zone.js [duplicate]违规点击处理程序采用 angular 5 和 chrome zone.js [重复]
【发布时间】:2020-05-14 00:14:33
【问题描述】:

我有一个使用 @angular/cli 创建的 Angular 5 项目,在开发模式下运行应用程序时,当我单击显示组件的选项卡时,我在 chrome 控制台中收到此消息

[Violation]“点击”处理程序耗时 289 毫秒

【问题讨论】:

    标签: angular


    【解决方案1】:

    你的问题很奇怪,我明白这一点。您需要一个按钮来允许您显示或不显示组件。 如果这是你的答案,那就很简单了。在您的 FileNamecomponent.ts 中设置一个布尔变量

    public showComponent:boolean = false;
    

    然后在你的 FileNamecomponent.html 中使用按钮标签来调用一个切换你的标志的事件,以及一个 *ngIf 实例来显示你的组件。

    <button type="button" (click)="showComponent = !showComponent"></button>
    <div *ngIf="showComponent">
       <app-OtheComponentName></app-OtherComponentName>
    </div>
    

    -app-OtherComponentName - 表示你的组件的选择器,你可以在@Component 装饰器中找到

    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.scss']
    });
    

    我希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-06
      • 2017-10-18
      • 1970-01-01
      • 2015-02-17
      • 1970-01-01
      • 1970-01-01
      • 2017-07-02
      • 1970-01-01
      相关资源
      最近更新 更多