Angular2 Recursive Templates in javascript

后端 未结 1 1132
日久生厌
日久生厌 2021-01-14 01:02

I have been trying to follow this tutorial to create a nested tree view. The tutorial is in typescript while I am trying to do a similar thing in javascript with Angular2. <

相关标签:
1条回答
  • 2021-01-14 01:50

    This question has been answered a few times

    First of all classes are not hoisted. Quoting from MDN

    An important difference between function declarations and class declarations is that function declarations are hoisted and class declarations are not. You first need to declare your class and then access it [...]

    The documentation for forwardRef says

    For instance, forwardRef is used when the token which we need to refer to for the purposes of DI is declared, but not yet defined. It is also used when the token which we use when creating a query is not yet defined.

    So it's as easy as adding forwardRef to your code

    directives : [ng.core.forwardRef(function() { return TreeView; })]
    

    You can read more about this subject

    • Forward references in Angular 2
    • Others questions from StackOverflow
    0 讨论(0)
提交回复
热议问题