Adding / Removing components on the fly

前端 未结 1 1504
Happy的楠姐
Happy的楠姐 2020-12-03 08:44

I need to be able to add & remove Angular components on the fly. To do so, I\'m using loadIntoLocation and dispose methods, like it:

Adding a component (from a l

相关标签:
1条回答
  • 2020-12-03 09:19

    As suggested by Tim,

    quoting @tbosch's comment

    Angular reuses previously created DOM elements by default

    So to avoid this behavior, taken from the comment as well, you can use APP_VIEW_POOL_CAPACITY and assign it 0 as value.

    bootstrap(MyApp, [provide(APP_VIEW_POOL_CAPACITY, {useValue: 0})])
    

    Update

    Note that since beta.1 APP_VIEW_POOL_CAPACITY was removed by #5993 and the DOM is being recreated correctly.

    0 讨论(0)
提交回复
热议问题