[@.disabled]="true" 导致控制台错误

[@.disabled]="true" causes console errors

我想在某些时候禁用 angular 动画,因此找到了 [@.disabled]="isDisabled"docs.

所以我想像这样使用它:[@.disabled]="true"(只是为了测试它),但我不断收到错误消息:

错误文本:

ERROR DOMException: Failed to execute 'setAttribute' on 'Element': '[@.s' is not a valid attribute name.
    at DefaultDomRenderer2.push.../../node_modules/@angular/platform-browser/fesm5/platform-browser.js.DefaultDomRenderer2.setAttribute (http://localhost:4200/vendor.js:134848:16)
    at AnimationRenderer.push.../../node_modules/@angular/platform-browser/fesm5/animations.js.BaseAnimationRenderer.setAttribute (http://localhost:4200/vendor.js:133467:23)
    at DebugRenderer2.push.../../node_modules/@angular/core/fesm5/core.js.DebugRenderer2.setAttribute (http://localhost:4200/vendor.js:85125:23)
    at createElement (http://localhost:4200/vendor.js:81803:22)
    at createViewNodes (http://localhost:4200/vendor.js:84036:26)
    at createEmbeddedView (http://localhost:4200/vendor.js:83983:5)
    at callWithDebugContext (http://localhost:4200/vendor.js:84997:25)
    at Object.debugCreateEmbeddedView [as createEmbeddedView] (http://localhost:4200/vendor.js:84521:12)
    at TemplateRef_.push.../../node_modules/@angular/core/fesm5/core.js.TemplateRef_.createEmbeddedView (http://localhost:4200/vendor.js:82564:38)
    at ViewContainerRef_.push.../../node_modules/@angular/core/fesm5/core.js.ViewContainerRef_.createEmbeddedView (http://localhost:4200/vendor.js:82430:35)

代码:

  <ng-container *ngIf="!something" [@.disabled]="true">
    ....
    <div [@fadingListAnimation]="otherthing">

是否缺少导入?为什么说''[@.s' is not a valid attribute name. 属性是@.disabled?

您必须从 ng-container 中删除禁用的动画,因为这些容器不会在最终的 HTML 页面上呈现。

你不能为不存在的东西制作动画!