【问题标题】:Export HTML inside DIV to file using AngularJS + NodeJS使用 AngularJS + NodeJS 将 DIV 中的 HTML 导出到文件
【发布时间】:2018-07-09 06:16:39
【问题描述】:

我目前的项目有点问题......如果这有点含糊,我深表歉意,因为我对如何开始这部分一无所知。

我有以下示例 HTML

<div id="exportme">
    I need to be exported
    <br />
    To a HTML document
</div>
<button ng-click="exportDocument()">Export DIV</button>

我想要发生的是,当我单击 exportDocument() 按钮时,该 DIV 中的内容将导出到位于服务器上的 html 文件(/tmp 或其他东西)

我不知道如何去做这样的事情,任何帮助将不胜感激。

使用: NodeJS 最新 AngularJS 1.6.4

【问题讨论】:

  • 对不起!它是页面的一部分,所以用户去 www.bla/#!/PAGE 并且会有那个 div,一旦点击就会导出所说的 html。
  • 我认为您需要使用document.getElementById("exportme") 将其拉出,然后使用.outerHTML 将其转换为字符串并将其发送到NodeJS(这超出了我的范围),可能使用$http.post(url,data)
  • 是的!有道理,我怎么没想到!多谢,伙计! :)

标签: javascript html angularjs node.js export


【解决方案1】:

这是一个没有 NodeJS 部分的工作演示

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>

<body>
  <div ng-app="myApp" ng-controller="demo">
    <div id="exportme">
      I need to be exported
      <br /> To a HTML document
    </div>
    <button ng-click="exportDocument()">Export DIV</button>
    <pre>
      {{a}}
    </pre>
  </div>
  <script>
    var app = angular.module('myApp', []);
    app.controller('demo', function($scope,$http) {
      $scope.exportDocument = function() {
        $scope.a = document.getElementById("exportme").outerHTML;
        // TODO: send $scope.a to NodeJS
        // $http.post(url,$scope.a);
      };
    });
  </script>
</body>

</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-27
    • 1970-01-01
    • 2020-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-14
    • 1970-01-01
    相关资源
    最近更新 更多