Allow some custom Angular2 elements

Let's say I would like to allow specific user elements (for example):

@Component({
  selector: 'transcludor',
  template: `
    <div class='transcludor'>
      <span class='slot-one'>
        <ng-content select='slot-one'></ng-content>
      </span>
      <span class='slot-two'>
        <ng-content select='slot-two'></ng-content>
      </span>
    </div>
  `})
export class Transcludor{
//stuff goes here
end

What I then use with:

<transcludor>
  <slot-one>
    stuff
  </slot-one>
  <slot-two>
    stuff
  </slot-two>
</transcludor>

This fails:

polyfills.js:3 Unhandled Promise rejection: Template parse errors:
'slot-one' is not a known element:

Now adding CUSTOM_ELEMENTS_SCHEMAto my schema @NgModulefixes the problem, but also allows you to use any and all custom elements.

Is it possible to define a specific set of allowed user elements (which are not in themselves components) to expand authority (for example).

eg. I would like: <slot-one></slot-one>and <slot-two></slot-two>, but for <slot-three></slot-three>, to throw the above exception.

Bonus points if they can be tied to specific contexts (for example, inside a component transcludor.)

+4

Source: https://habr.com/ru/post/1677537/


All Articles