我想在Angular组件中调用saveFile()
函数,但它不起作用。我做错了什么?
这是我的Angular组件的html模板:
<div class="Tree" onload="saveFile()">
<tree-root [nodes]="nodes">
<ng-template #treeNodeTemplate let-node let-index="index">
<a routerLinkActive="active" ><span>{{ node.data.description }}</span></a>
</ng-template>
</tree-root>
</div>
<router-outlet></router-outlet>
<script src="FileSaver.js"></script>
<script type="text/javascript">
function saveFile(){
var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
saveAs(blob, "hello world.txt");
}
</script>