Render a directive inside another directive (within repeater template)

前端 未结 2 2026
没有蜡笔的小新
没有蜡笔的小新 2021-02-09 08:01

I am trying to render a directive inside another directive (not sure if the repeater inside the template is working this), and it seems to just output as text rather than compil

2条回答
  •  滥情空心
    2021-02-09 08:47

    This is in part a timing problem...I think that by the time it's resolving the {{}} expressions, it's already parsed out and rendered directives. It's not the nesting or the repeater that are the problem, per se.

    What you're after here, though, is 'decide which directive to render based on the value of a variable'. There are a couple ways to do that.

    Here's one that should work, though it might not scale as nicely as you'd like:

    Other options for similar tricks: it looks like you could use ngBindTemplate to take a string from your data and use it as the template for an element. This would probably permit some tricky (and illegible) behavior.

    You can specify a directive for an element as a class, but I don't know whether using ngClass to do this would allow you to dynamically select the directive, or whether that would come too late in the pipeline.

提交回复
热议问题