Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角材料2中的md工作台不工作_Angular_Angular Material2 - Fatal编程技术网

Angular 角材料2中的md工作台不工作

Angular 角材料2中的md工作台不工作,angular,angular-material2,Angular,Angular Material2,我只是尝试在Angular Material beta 2.0.0-beta.8中使用新引入的datatable,但我无法让它工作,因为我遇到了以下错误: ERROR TypeError: Cannot read property 'columnsChange' of undefined at MdTable.webpackJsonp.../../../cdk/@angular/cdk.es5.js.CdkTable.ngAfterContentInit (cdk.es5.js:1950) at

我只是尝试在Angular Material beta 2.0.0-beta.8中使用新引入的datatable,但我无法让它工作,因为我遇到了以下错误:

ERROR TypeError: Cannot read property 'columnsChange' of undefined
at MdTable.webpackJsonp.../../../cdk/@angular/cdk.es5.js.CdkTable.ngAfterContentInit (cdk.es5.js:1950)
at callProviderLifecycles (core.es5.js:11174)
at callElementProvidersLifecycles (core.es5.js:11155)
at callLifecycleHooksChildrenFirst (core.es5.js:11139)
at checkAndUpdateView (core.es5.js:12239)
at callViewAction (core.es5.js:12601)
at execEmbeddedViewsAction (core.es5.js:12559)
at checkAndUpdateView (core.es5.js:12237)
at callViewAction (core.es5.js:12601)
at execComponentViewsAction (core.es5.js:12533)
at checkAndUpdateView (core.es5.js:12242)
at callViewAction (core.es5.js:12601)
at execEmbeddedViewsAction (core.es5.js:12559)
at checkAndUpdateView (core.es5.js:12237)
at callViewAction (core.es5.js:12601)
我将MdTableModule和CdkTableModule都导入了我的应用程序模块

数据源实现如下所示:

 import {OnInit, Component} from "@angular/core";
import {SetupSummaryService} from "./setupSummaryService";
import {BehaviorSubject} from 'rxjs/BehaviorSubject';
import {Observable} from 'rxjs/Observable';
import {DataSource} from "@angular/cdk";
import 'rxjs/add/operator/startWith';
import 'rxjs/add/observable/merge';
import 'rxjs/add/operator/map';


@Component({
  templateUrl: 'setupSummary.component.html',
  styleUrls: ['setupSummary.component.scss'],
  providers: [SetupSummaryService]
})

export class SetupSummaryComponent implements OnInit {

  displayedColumns = ['userId', 'userName', 'progress', 'color'];
  exampleDatabase = new ExampleDatabase();
  dataSource: ExampleDataSource | null;
  constructor() {
  }

  ngOnInit(): void {
        this.dataSource = new ExampleDataSource(this.exampleDatabase);

  }

}
/** Constants used to fill up our data base. */
const COLORS = ['maroon', 'red', 'orange', 'yellow', 'olive', 'green', 'purple',
  'fuchsia', 'lime', 'teal', 'aqua', 'blue', 'navy', 'black', 'gray'];
const NAMES = ['Maia', 'Asher', 'Olivia', 'Atticus', 'Amelia', 'Jack',
  'Charlotte', 'Theodore', 'Isla', 'Oliver', 'Isabella', 'Jasper',
  'Cora', 'Levi', 'Violet', 'Arthur', 'Mia', 'Thomas', 'Elizabeth'];

export interface UserData {
  id: string;
  name: string;
  progress: string;
  color: string;
}
/** An example database that the data source uses to retrieve data for the table. */
export class ExampleDatabase {
  /** Stream that emits whenever the data has been modified. */
  dataChange: BehaviorSubject<UserData[]> = new BehaviorSubject<UserData[]>([]);
  get data(): UserData[] { return this.dataChange.value; }

  constructor() {
    // Fill up the database with 100 users.
    for (let i = 0; i < 100; i++) { this.addUser(); }
  }

  /** Adds a new user to the database. */
  addUser() {
    const copiedData = this.data.slice();
    copiedData.push(this.createNewUser());
    this.dataChange.next(copiedData);
  }

  /** Builds and returns a new User. */
  private createNewUser() {
    const name =
      NAMES[Math.round(Math.random() * (NAMES.length - 1))] + ' ' +
      NAMES[Math.round(Math.random() * (NAMES.length - 1))].charAt(0) + '.';

    return {
      id: (this.data.length + 1).toString(),
      name: name,
      progress: Math.round(Math.random() * 100).toString(),
      color: COLORS[Math.round(Math.random() * (COLORS.length - 1))]
    };
  }
}

/**
 * Data source to provide what data should be rendered in the table. Note that the data source
 * can retrieve its data in any way. In this case, the data source is provided a reference
 * to a common data base, ExampleDatabase. It is not the data source's responsibility to manage
 * the underlying data. Instead, it only needs to take the data and send the table exactly what
 * should be rendered.
 */
export class ExampleDataSource extends DataSource<any> {
  constructor(private _exampleDatabase: ExampleDatabase) {
    super();
  }

  /** Connect function called by the table to retrieve one stream containing the data to render. */
  connect(): Observable<UserData[]> {
    return this._exampleDatabase.dataChange;
  }

  disconnect() {}
}
从“@angular/core”导入{OnInit,Component};
从“/SetupSummaryService”导入{SetupSummaryService};
从'rxjs/BehaviorSubject'导入{BehaviorSubject};
从“rxjs/Observable”导入{Observable};
从“@angular/cdk”导入{DataSource}”;
导入'rxjs/add/operator/startWith';
导入“rxjs/add/observable/merge”;
导入'rxjs/add/operator/map';
@组成部分({
templateUrl:'setupSummary.component.html',
样式URL:['setupSummary.component.scss'],
提供者:[设置摘要服务]
})
导出类SetupSummaryComponent实现OnInit{
displayedColumns=['userId'、'userName'、'progress'、'color'];
exampleDatabase=新建exampleDatabase();
数据源:ExampleDataSource |空;
构造函数(){
}
ngOnInit():void{
this.dataSource=新的ExampleDataSource(this.exampleDatabase);
}
}
/**用于填充数据库的常量*/
常量颜色=[‘栗色’、‘红色’、‘橙色’、‘黄色’、‘橄榄色’、‘绿色’、‘紫色’,
“紫红色”、“青柠色”、“青绿色”、“水绿色”、“蓝色”、“海军蓝”、“黑色”、“灰色”];
常量名称=['Maia'、'Asher'、'Olivia'、'Atticus'、'Amelia'、'Jack',
“夏洛特”、“西奥多”、“艾拉”、“奥利弗”、“伊莎贝拉”、“贾斯珀”,
‘科拉’、‘李维’、‘紫罗兰’、‘亚瑟’、‘米娅’、‘托马斯’、‘伊丽莎白’;
导出接口用户数据{
id:字符串;
名称:字符串;
进展:字符串;
颜色:字符串;
}
/**数据源用于检索表数据的示例数据库*/
导出类示例数据库{
/**每当数据被修改时发出的流*/
dataChange:BehaviorSubject=新的BehaviorSubject([]);
get data():UserData[]{返回this.dataChange.value;}
构造函数(){
//用100个用户填充数据库。
对于(设i=0;i<100;i++){this.addUser();}
}
/**将新用户添加到数据库*/
addUser(){
const copiedData=this.data.slice();
copiedData.push(this.createNewUser());
this.dataChange.next(复制数据);
}
/**生成并返回一个新用户*/
私有createNewUser(){
常数名=
名称[Math.round(Math.random()*(NAMES.length-1))]+''+
名称[Math.round(Math.random()*(NAMES.length-1))].charAt(0)+';
返回{
id:(this.data.length+1).toString(),
姓名:姓名,,
进度:Math.round(Math.random()*100).toString(),,
颜色:颜色[Math.round(Math.random()*(COLORS.length-1))]
};
}
}
/**
*数据源提供应在表中呈现的数据。请注意,数据源
*可以以任何方式检索其数据。在这种情况下,数据源提供了一个参考
*到公共数据库,例如数据库。数据源不负责管理
*基础数据。取而代之的是,它只需要获取数据并发送表所需的数据
*应该被渲染。
*/
导出类ExampleDataSource扩展了DataSource


作为实现此功能的指南。

您必须在
html
文件中添加以下行:


因此,您的
html
文件如下所示:

 import {OnInit, Component} from "@angular/core";
import {SetupSummaryService} from "./setupSummaryService";
import {BehaviorSubject} from 'rxjs/BehaviorSubject';
import {Observable} from 'rxjs/Observable';
import {DataSource} from "@angular/cdk";
import 'rxjs/add/operator/startWith';
import 'rxjs/add/observable/merge';
import 'rxjs/add/operator/map';


@Component({
  templateUrl: 'setupSummary.component.html',
  styleUrls: ['setupSummary.component.scss'],
  providers: [SetupSummaryService]
})

export class SetupSummaryComponent implements OnInit {

  displayedColumns = ['userId', 'userName', 'progress', 'color'];
  exampleDatabase = new ExampleDatabase();
  dataSource: ExampleDataSource | null;
  constructor() {
  }

  ngOnInit(): void {
        this.dataSource = new ExampleDataSource(this.exampleDatabase);

  }

}
/** Constants used to fill up our data base. */
const COLORS = ['maroon', 'red', 'orange', 'yellow', 'olive', 'green', 'purple',
  'fuchsia', 'lime', 'teal', 'aqua', 'blue', 'navy', 'black', 'gray'];
const NAMES = ['Maia', 'Asher', 'Olivia', 'Atticus', 'Amelia', 'Jack',
  'Charlotte', 'Theodore', 'Isla', 'Oliver', 'Isabella', 'Jasper',
  'Cora', 'Levi', 'Violet', 'Arthur', 'Mia', 'Thomas', 'Elizabeth'];

export interface UserData {
  id: string;
  name: string;
  progress: string;
  color: string;
}
/** An example database that the data source uses to retrieve data for the table. */
export class ExampleDatabase {
  /** Stream that emits whenever the data has been modified. */
  dataChange: BehaviorSubject<UserData[]> = new BehaviorSubject<UserData[]>([]);
  get data(): UserData[] { return this.dataChange.value; }

  constructor() {
    // Fill up the database with 100 users.
    for (let i = 0; i < 100; i++) { this.addUser(); }
  }

  /** Adds a new user to the database. */
  addUser() {
    const copiedData = this.data.slice();
    copiedData.push(this.createNewUser());
    this.dataChange.next(copiedData);
  }

  /** Builds and returns a new User. */
  private createNewUser() {
    const name =
      NAMES[Math.round(Math.random() * (NAMES.length - 1))] + ' ' +
      NAMES[Math.round(Math.random() * (NAMES.length - 1))].charAt(0) + '.';

    return {
      id: (this.data.length + 1).toString(),
      name: name,
      progress: Math.round(Math.random() * 100).toString(),
      color: COLORS[Math.round(Math.random() * (COLORS.length - 1))]
    };
  }
}

/**
 * Data source to provide what data should be rendered in the table. Note that the data source
 * can retrieve its data in any way. In this case, the data source is provided a reference
 * to a common data base, ExampleDatabase. It is not the data source's responsibility to manage
 * the underlying data. Instead, it only needs to take the data and send the table exactly what
 * should be rendered.
 */
export class ExampleDataSource extends DataSource<any> {
  constructor(private _exampleDatabase: ExampleDatabase) {
    super();
  }

  /** Connect function called by the table to retrieve one stream containing the data to render. */
  connect(): Observable<UserData[]> {
    return this._exampleDatabase.dataChange;
  }

  disconnect() {}
}

身份证件
{{row.id}}
进展
{{row.progress}}}%
名称
{{row.name}
颜色
{{row.color}}

你能创建一个
plunker吗
@Aravind,我试过创建plunker,但它不允许我添加角度材质beta 2.0.0-beta.8。抱歉,我是plunker的新手,我尝试从软件包中添加它,但它不可用。是否有其他方法可以执行此操作。@user1188867您可以尝试在此处重新创建它: