Can $transclude be used to get interpolated text content?

非 Y 不嫁゛ 提交于 2019-12-13 17:21:46

问题


Is there a way to get transclude content after it has been interpolated using $transclude in a controller? I want the transclude to be performed without any alteration, but I need the interpolated value.

For example I have a component that transcludes an interpolated string:

<my-transclude-component>{{ vm.someTextToTransclude }}</my-transclude-component>

Using $transclude in my controller I can do this to get the transcluded content, but it gives the uninterpolated value of {{ vm.someTextToTransclude }} as a string instead of Hello World:

vm.$onInit = function() {

    $transclude(function(clone) { 
        console.log(clone.text()); 
    });
}

I know I can bind it to the component, but that's not the point of this question. Currently this is how it is being done since the content isn't interpolated using $transclude:

<my-transclude-component my-text="{{ vm.someTextToTransclude }}"></my-transclude-component>

来源:https://stackoverflow.com/questions/42080076/can-transclude-be-used-to-get-interpolated-text-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!