How to use Angular structural directive with multiple inputs

前端 未结 3 1088
栀梦
栀梦 2020-12-12 22:24

I want to implement something similar with angular-permisssion. And with requirement to control the element\'s existance, I need to use angular structural directive.

3条回答
  •  攒了一身酷
    2020-12-12 22:33

    Then one problem occurs: template syntax doesn't support pure key-value inputs:

    True

    A stupid temporary solution is add a useless variable declaration.

    I think you are using this in a way it was not meant to be.

    From the docs:

    The microsyntax parser title-cases all directives and prefixes them with the directive's attribute name, such as ngFor. For example, the ngFor input properties, of and trackBy, become ngForOf and ngForTrackBy, respectively. That's how the directive learns that the list is heroes and the track-by function is trackById.

    https://angular.io/guide/structural-directives#microsyntax-examples

    Bottom line is in the context of your question, the microsyntax accepts "expression", followed by optional "keyed expression"s and I'm afraid those are your only options.

    One could of course pass an object as the first expression—similar to ngIf—, the difference being you can teach your directive how to evaluate the expression:

    *permissionIf="{ only: 'whatever', except: ['things', 'stuff'] }"

提交回复
热议问题