小编mal*_*awi的帖子

使用JavaScript/JQuery将html表数据导出到Excel在chrome浏览中无法正常工作

我在速度模板中有一个HTML表格.我想使用java脚本或jquery,comatibale和所有浏览器将html表数据导出到excel.我正在使用下面的脚本

<script type="text/javascript">
function ExportToExcel(mytblId){
       var htmltable= document.getElementById('my-table-id');
       var html = htmltable.outerHTML;
       window.open('data:application/vnd.ms-excel,' + encodeURIComponent(html));
    }
</script>
Run Code Online (Sandbox Code Playgroud)

这个脚本在Mozilla Firefox中工作正常,它弹出一个excel对话框,并要求打开或保存选项.但是当我在Chrome浏览器中测试相同的脚本时,它没有按预期工作,当点击按钮时,没有弹出的Excel.数据被下载到一个带有"文件类型:文件"的文件中,没有像.xls那样的扩展名 在chrome控制台中没有错误.

Jsfiddle的例子:

http://jsfiddle.net/insin/cmewv/

这在mozilla中运行良好,但在chrome中不行.

Chrome浏览器测试用例:

第一张图片:我点击导出到Excel按钮

第一张图片:我点击导出到Excel按钮

结果:

结果

html javascript excel jquery google-chrome

83
推荐指数
9
解决办法
43万
查看次数

Angular io(4)*ng为第一个也是最后一个

我试图判断a中的项是否*ngFor是容器样式的第一个或最后一个元素.有没有办法做这样的事情?

<md-expansion-panel *ngFor="let item of items" *ngClass="{ 'first' : item.isFirst }">
  <content></content>
</md-expansion-panel>
Run Code Online (Sandbox Code Playgroud)

感谢您提供的任何帮助!

ngfor angular

22
推荐指数
2
解决办法
2万
查看次数

providedIn any 和 root 和有什么不一样

在 Angular 9 中,可注入装饰器选项providedIn有一个名为any. root和 和有any什么区别?

在我使用的情况下,服务是否被视为单例any

@Injectable({providedIn: 'any'})
class UsefulService {
}
Run Code Online (Sandbox Code Playgroud)

typescript angular-services angular angular-dependency-injection

10
推荐指数
3
解决办法
4605
查看次数

过滤材料表中的不同列

我正在尝试向材质表添加不同的过滤器.更确切地说,我正在尝试重现类似于以下GIF的内容

图片描述

为此,我在以下Github线程中关注irowbin的响应,但根据他的指导原则,我无法真正生成我想要的内容

在Stackblitz或Github上有任何工作示例,所以我可以在mattable中关注并创建多个搜索过滤器吗?

material-design angular-material angular angular-material-5 angular-material-6

9
推荐指数
1
解决办法
6873
查看次数

Angular 6 Error trying to diff '[object Object]'. Only arrays and iterables are allowed

I think my Problem is that the API delivers an Object instead of an array. So i need to Modify the Object to be an Array ?

How could this be done ? Object.assign ? Or Pipe ? Does anyone have a proper example ? I'am still learning Angular this is my second Project so i need some help ;)

thy so far !

Here is my code

getting data from API ..cant change the API it delivers an Object …

api fetch ngfor primeng angular

8
推荐指数
1
解决办法
3万
查看次数

何为angular 6项目全局添加自定义CSS文件

如果我添加在angular.json文件中

"styles": [
  "src/styles.css",
  "src/utility/vendor/bootstrap/css/bootstrap.css",
  "src/utility/vendor/font-awesome/css/fontawesome-all.min.css",
  "src/utility/vendor/animate.css/animate.min.css",
  "src/utility/vendor/slick-carousel/slick/slick.css",
  "src/utility/css/front.css",
  "src/utility/css/codepen.css"
],
Run Code Online (Sandbox Code Playgroud)

这些文件仅可用于index.html文件访问,而不能访问app.component.html或任何组件,甚至其他组件也不会使用与index.html相同的内容进行渲染,但是index.html可以正常工作

css angular angular6

8
推荐指数
1
解决办法
6955
查看次数

ngAfterViewInit 不起作用或者我做错了什么

我的 ngAfterViewInit 函数未按预期工作。我感觉我在这里错过了一些东西。

  ngOnInit() {
   this.dataService.getUsers().subscribe((users) => {this.users = users) ;  
  }

  ngAfterViewInit() {
    if (document.getElementById('target')) {
        document.getElementById('target').scrollIntoView({
          behavior: 'auto',
          block: 'center',
          inline: 'center',
       });
   }
Run Code Online (Sandbox Code Playgroud)

所以基本上,在视图完成加载后,我使用ngAfterViewInint()函数滚动到当前项目。在里面ngOnInit(),如果我不打电话subscribe(),只是在那里放一个变量。它工作得很好。但我所问的情况并非如此。

setTimeOut()我通过使用inside解决了这个问题ngAfterViewInit()。但我不喜欢它。我不喜欢它依赖于超时这一事实。我认为会有更好的解决方案。有理想吗?谢谢大家。

javascript typescript angular

8
推荐指数
2
解决办法
2万
查看次数

找不到模块“@angular/common/http”

我已将 npm 升级到最新版本。我的 Visual Studio 应用程序中的 npm 文件夹读取 v6.0.3,而我的 package.json 文件也对应于此版本 6.0.3。

但是每当我运行我的应用程序时,我都会收到错误“无法在浏览器上找到模块”

请参阅错误图片

我相信 HttpClient 在 3x 以上的版本中使用,但显然安装了更高的版本。

应用程序模块.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { RouterModule } from '@angular/router';

import { AppComponent } from './components/app/app.component';
import { NavMenuComponent } from './components/navmenu/navmenu.component';
import { HomeComponent } from './components/home/home.component';
import { FetchDataComponent } from './components/fetchdata/fetchdata.component';
import { CounterComponent } from './components/counter/counter.component';
import …
Run Code Online (Sandbox Code Playgroud)

npm package.json angular

7
推荐指数
2
解决办法
2万
查看次数

打字稿:无法将默认参数值设置为 false

我有一个方法,它有一些可选参数,像这样,

initializeInteraction(opts: { type?: string; freehand?:boolean= false }) {
    this._draw = this.drawService.initDraw({ drawtype: opts.type });
    this._drawInteraction = this._draw.interaction;
    this.mapService.addVector(this._draw.vector);
    this.mapService.addInteraction(this._drawInteraction);
  } 
Run Code Online (Sandbox Code Playgroud)

我想仅在需要时将 的值设置freehandtrue,否则我希望将其设置为false

但是当我宣布这一点时

initializeInteraction(opts: { type: string; freehand?:boolean= false }) {}
Run Code Online (Sandbox Code Playgroud)

我收到一个错误

[ts] A type literal property cannot have an initializer. [1247]
Run Code Online (Sandbox Code Playgroud)

typescript angular angular5

7
推荐指数
1
解决办法
1万
查看次数

粘性标题无法与Primeng中的可调整大小的列一起使用?

我正在尝试实现列大小调整stick header。但是,如果我不使用列大小调整,则粘性标头可以很好地工作。如果同时实现这两种方法,则列调整大小是有效的,但粘性标头不起作用。

我使用了primeng的以下CSS作为粘性标头。

  :host ::ng-deep .ui-table .ui-table-thead > tr > th {
        position: -webkit-sticky;
        position: sticky;
        top: 70px;
    }

    @media screen and (max-width: 64em) {
        :host ::ng-deep .ui-table .ui-table-thead > tr > th {
            top: 100px;
        }
    }
Run Code Online (Sandbox Code Playgroud)

对于colum调整大小,我使用了以下代码[resizableColumns]="true"pResizableColumn

  <p-table [columns]="cols" [value]="cars1" [resizableColumns]="true">
    ...
     <th *ngFor="let col of columns" pResizableColumn>
Run Code Online (Sandbox Code Playgroud)

如果我删除resizbleColumnspResizableColumn粘性标头工作正常。我怎样才能使它同时起作用呢?这是stackblitz演示

html css primeng angular primeng-datatable

7
推荐指数
2
解决办法
393
查看次数