Renderer multiple selectRootElement Issue

后端 未结 2 1916
隐瞒了意图╮
隐瞒了意图╮ 2020-12-03 00:37

I am trying to use Renderer.selectRootElement to get some elements from my Component, as described here.

Everything works fine, unless I select only one element (pln

2条回答
  •  感情败类
    2020-12-03 00:51

    If you want to preserve content then use the second boolean parameter to true, like this: (using Angular 6)

    let activeLi = this.renderer.selectRootElement('ul.ddl>li.active', true);
    

    See the detail from API

         /*
         * Implement this callback to prepare an element to be bootstrapped
         * as a root element, and return the element instance.
         * @param selectorOrNode The DOM element.
         * @param preserveContent Whether the contents of the root element
         * should be preserved, or cleared upon bootstrap (default behavior).
         * Use with `ViewEncapsulation.ShadowDom` to allow simple native
         * content projection via `` elements.
         * @returns The root element.
         */
    

    abstract selectRootElement(selectorOrNode: string | any, preserveContent?: boolean): any;

    Thanks Eric to bring in notice that it removes content by default!

提交回复
热议问题