How to use Angular structural directive with multiple inputs

前端 未结 3 1091
栀梦
栀梦 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:27

    The input names need all to be prefixed with the selector of the directive, followed by the input name capitalized (i.e. permissionIfExcept). Example:

      @Directive({
        selector: '[permissionIf]'
      })
      export class PermissionIfDirective implements AfterContentInit {
    
        private _permissionIf:string[];
        @Input() 
        set permissionIf(value: string[]) {
          this._permissionIf=value;
          console.log('permissionIf: ', value);
        }
    
        private _except:string;
        @Input() 
        set permissionIfExcept(value: string) {
          this._except = value;
          console.log('except: ', value);
        }
      }
    

    To use them with the '*' syntax:

    Note here you're using the name following the prefix uncapitalized (i.e. except). Also note the : in the assignment.

    The explicit syntax (using template) would look like this:

    
    

    but with it could look like

    
      

    Plunker example

    See also the source of NgFor as an example.

提交回复
热议问题