【发布时间】:2015-06-05 11:58:11
【问题描述】:
我创建了一个JSBIN,一切正常,但问题是,我无法重命名文件并添加扩展名。
另一个问题是数据仅来自静态 DOM,而不是来自我使用控制器放置的 ng-repeat。
var app = angular.module('app', []);
app.controller('ctrl', function($scope) {
$scope.data = [{
one: "Column One",
two: "Column Two",
three: "Column Three"
}, {
one: "Column One",
two: "Column Two",
three: "Column Three"
}, {
one: "Column One",
two: "Column Two",
three: "Column Three"
}];
});
app.directive("myExportData", function() {
return {
restrict: "EA",
link: function(scope, ele, attr) {
ele.attr('value', "Export Table data into Excel");
ele.bind('click', function() {
console.log($('#dvData').html());
window.open('data:application/vnd.ms-excel,' + $('#dvData').html());
});
}
};
});
HTML 类似
<body ng-controller="ctrl">
<div id="dvData">
<table>
<tr>
<th>One</th>
<th>Two</th>
<th>Three</th>
</tr>
<tr ng-repeat="obj in data">
<td>{{obj.one}}</td>
<td>{{obj.two}}</td>
<td>{{obj.three}}</td>
</tr>
</table>
<input my-export-data type="button" id="btnExport" />
</div>
</body>
【问题讨论】:
标签: javascript angularjs