角$编译为字符串以生成代码

Dav*_*wys 5 code-generation angularjs

我正在使用Angular构建通用代码生成器

我有动态数据结构和模板,旨在构建不同类型的代码。HTML,C#,SQL,Javascript,CSS,Ruby。

在此处输入图片说明

我已经获得$ compile函数作为指令的一部分工作,并且可以在Angular页面中注入元素。

我真正需要的是生成一个简单的字符串的生成。

我读过的每一篇文章都谈到获取编译后的输出并将其注入角度管道,这不是我的要求。

有谁知道我可以从已经与合并范围数据合并的已编译模板中提取一个简单的字符串吗?

angular.module('workibleServerApp')
  .directive('generateDynamicTemplate', ['$compile', function ($compile) {
      return {
          scope: true,
          data: '=',
          rawTemplate: '=',
          restrict: 'E',
          link: function (scope, element, attrs) {

              scope.$watchGroup([attrs.data, attrs.rawTemplate], function (newValues) {

                  scope.data = newValues[0];
                  var rawTemplate = newValues[1];

                  element.html('');
                  //element.html('<textarea id="outputRaw" name="outputRaw" class="form-control" rows="12">');

                  if (!_.isEmpty(scope.data) && !_.isEmpty(rawTemplate)) {
                      var tl = angular.element(rawTemplate);
                      var compiled = $compile(tl)(scope);
                      element.append(compiled);

                      scope.convertToString = compiled;
                  }
                  //element.append('</textarea>');
              });


          }
      };
  }]);
Run Code Online (Sandbox Code Playgroud)

没有填充convertToString

              <div class="col-md-6">
                    <h6><strong>Output</strong></h6>
                    <!-- This renders output from the directive, all GOOD -->
                    <generate-dynamic-template data="model.richData" raw-template="model.template"></generate-dynamic-template>

<!-- Neither of these work, This Does not work -->
<pre>
{{convertToString}}
</pre>
                    <textarea>{{convertToString}}</textarea>

                    <!--<textarea id="output" name="output" ng-model="model.output" rows="20" placeholder="Output" class="form-control input-sm"></textarea>-->
                </div>
Run Code Online (Sandbox Code Playgroud)