面对错误:angular4错误:val.slice不是函数?

时间:2017-07-28 04:52:02

标签: angular

我遇到了这个错误:

单击refresh()或delectRole(i)按钮错误:

ERROR TypeError: val.slice is not a function
    at DataTable.set [as value] (datatable.js:508)

出了什么问题? 数据可以传输,但需要刷新才能显示

哪个值不是函数?我删除了' i'但它不起作用:

import { Component, OnInit, ViewChild } from '@angular/core';
import { Role } from '../domain/role';
import { RoleService } from '../service/role.service';
import { RequestOptions , Headers} from '@angular/http';
@Component({
    templateUrl: 'roleList.html',
      providers: [ConfirmationService]
    })
    export class RoleList implements OnInit  {
        public loading = false;
        roles: any;
        // 开启Switch
        active: boolean = true;
        delectSelectedIdJson: string;                         
        msgs: Message[] = [];                                 
        constructor(private roleService: RoleService, private confirmationService: ConfirmationService, ) { }
        ngOnInit() {
            this.loading = true;
            this.roleService.getRoleList({}).then(roles => {
                this.loading = false;
                this.roles = roles.all;
            });
        }
         // refresh
          refresh() {
            this.loading = true;
            this.roleService.getRoleList({}).then(roles => {this.roles = roles; this.loading = false; });
        }
        // delectRole
          delectRole(i) {
              this.loading = true;
              this.delectSelectedIdJson = JSON.stringify({'roleId': i});
              this.roleService.getRoleDelect(this.delectSelectedIdJson).then(roles => {
                       this.roles = roles;
                       if (roles.code === '0000') {
                          this.loading = false;
                          this.refresh();
                        } else if (roles.code === '4000') {
                           this.loading = false;

                            return false;
                        }
                    });
        }
    }

<a class="btn btn-default" (click)="delectRole(role[col.field])" *ngIf="roleDelete()"><i class="fa fa-trash"></i></a>

<a class="btn btn-default" (click)="refresh()"><i class="fa fa-refresh"></i>refresh</a>

0 个答案:

没有答案