Angular2: Creating child components programmatically

后端 未结 5 1514
心在旅途
心在旅途 2020-12-13 18:20

Question

How to create child components inside a parent component and display them in the view afterwards using Angular2? How to make sure the injectables

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-13 18:22

    This is generally not the approach I would take. Instead I would rely on databinding against an array that will render out more child components as objects are added to the backing array. Essentially child components wrapped in an ng-for

    I have an example here that is similar in that it renders a dynamic list of children. Not 100% the same, but seems like the concept is still the same:

    http://www.syntaxsuccess.com/viewarticle/recursive-treeview-in-angular-2.0

提交回复
热议问题