我对我当前的项目有点疑问......如果这有点模糊,我会道歉,因为我对如何开始这部分毫无头绪。
我有以下示例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
答案 0 :(得分:0)
这是一个没有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>