การประกาศหรือคำสั่งที่คาดว่าจะเกิดข้อผิดพลาดในไฟล์ typescript (เชิงมุม2)

ฉันกำลังพยายามสรุปค่าที่ป้อนในคอลัมน์ mat-table โดยใช้อินพุต

ฉันสร้างตารางที่มี 3 คอลัมน์: Account Id, Account Description และ Value ฉันได้สร้างไฟล์ JSON ในโฟลเดอร์ทรัพย์สินด้วยค่าสำหรับ acc_id และ acc_desc

จากนั้น ฉันเข้าถึงค่าเหล่านี้ในตารางของฉันสำหรับคอลัมน์ที่เกี่ยวข้อง

ฉันได้สร้างคอลัมน์ Value ที่ฉันกำหนดช่องป้อนข้อมูลไว้ด้วย

ถัดจากตาราง ฉันใช้ตารางธรรมดาที่มีสองช่อง โดยฉันต้องการหาผลรวมของค่าทั้งหมดที่ป้อนในคอลัมน์ Value

account.component.html

    <!-- Table starts here -->

<mat-card>
<div class="example-container mat-elevation-z8">

  <mat-table #table [dataSource]="dataSource1">

    <!-- Account No. Column -->
    <ng-container matColumnDef="acc_id">
      <mat-header-cell *matHeaderCellDef> Account ID. </mat-header-cell>
      <mat-cell *matCellDef="let element">{{element.acc_id}}</mat-cell>
    </ng-container>

    <!-- Account Description Column -->
    <ng-container matColumnDef="acc_des">
      <mat-header-cell *matHeaderCellDef> Account Description </mat-header-cell>
      <mat-cell *matCellDef="let element">{{element.acc_des }} </mat-cell>
    </ng-container>

        <!-- Value Column -->
    <ng-container matColumnDef="value">
      <mat-header-cell *matHeaderCellDef> Value </mat-header-cell>
      <mat-cell *matCellDef="let element">
     <ng-container>
       <input  [(ngModel)]="element.value">
     </ng-container> 
   </mat-cell>
    </ng-container>


    <mat-header-row *matHeaderRowDef="displayedColumns1" ></mat-header-row>
    <mat-row *matRowDef="let row; columns: displayedColumns1;" > </mat-row>

  </mat-table>

   <mat-grid-list cols="2" rowHeight="20:1">

  <mat-grid-tile style="align-self: left;"> Total</mat-grid-tile>
  <mat-grid-tile>{{calculation()}}</mat-grid-tile>

</mat-grid-list>

</div>
</mat-card>

account.component.ts

import {Component, OnInit} from '@angular/core';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import { ReactiveFormsModule, FormGroup,FormControl } from '@angular/forms';
import { MatTableDataSource} from '@angular/material';
import { AccountdetailService } from '../accountdetail.service';



@Component({
  selector: 'app-account',
  templateUrl: './account.component.html',
  styleUrls: ['./account.component.scss']
   })


export class AccountComponent implements OnInit {

element: string;
value: any;
constructor( private accdetailservice: AccountdetailService ) { }


  /* Table Starts here
  ---------------------- */

 displayedColumns1 = ['acc_id', 'acc_des', 'value'];
 dataSource1= new MatTableDataSource<Element>(ELEMENT_DATA);


calculation(){ 
return this.dataSource1.data.reduce((summ, v) => summ += parseInt(v.value), 0) 
}



 ngOnInit(){
  this.accdetailservice.accountdetails().subscribe(data =>
  var tempObject = data.map(obj => ({...obj, value: 0}));
  this.dataSource1.data = tempObject; );
 }
}

const ELEMENT_DATA: Element[] = [];

accountdetails.service.ts

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';


@Injectable()
export class AccountdetailService {

  constructor(private http:Http ) { }

  accountdetails()
  {
    return this.http.get('/assets/accountdetails.json')
    .map(result => result.json());
  }}

accountdetails.json

[
    {
        "acc_id": 1001,
        "acc_des": "aaa"

    },

    {
        "acc_id": 1002,
        "acc_des": "aaa"

    }
]

app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ReactiveFormsModule,FormsModule } from '@angular/forms';
import { HttpModule} from '@angular/http';

import { AppMaterialModule } from './app-material.module';


import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { AccountComponent } from './account/account.component';

import { AccountdetailService } from './accountdetail.service';


@NgModule({
  declarations: [
    AppComponent,
    AccountComponent    
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    ReactiveFormsModule,
    BrowserAnimationsModule,
    AppMaterialModule,
    FormsModule ,
    HttpModule   
  ],
  entryComponents:[ ],

  providers: [ AccountdetailService],
  bootstrap: [AppComponent]
})
export class AppModule { }

ฉันสามารถสรุปค่าที่ป้อนในคอลัมน์ค่าได้ แต่ฉันได้รับข้อผิดพลาดด้านล่าง

ป้อนคำอธิบายรูปภาพที่นี่

ใครสามารถบอกฉันได้ว่ามีอะไรหายไปในไวยากรณ์ของฉันในรหัสต่อไปนี้...

ngOnInit(){
  this.accdetailservice.accountdetails().subscribe(data =>
  var tempObject = data.map(obj => ({...obj, value: 0}));
  this.dataSource1.data = tempObject; );
 }

นี่คือผลงานของฉัน..

ป้อนคำอธิบายรูปภาพที่นี่


person Heena    schedule 02.03.2018    source แหล่งที่มา
comment
ฉันพยายามหลายวิธีเท่าที่จะทำได้ ... แต่ฉันไม่สามารถกำจัดข้อผิดพลาดนั้นได้ ... แม้ว่าแอปพลิเคชันของฉันจะทำงานอยู่ก็ตาม   -  person Heena    schedule 02.03.2018


คำตอบ (1)


person    schedule
comment
แต่ตอนนี้ฉันได้รับข้อผิดพลาดซึ่งก่อนหน้านี้ฉันโพสต์คำถามในลิงค์นี้ ...stackoverflow.com/questions/49044826/ - person Heena; 02.03.2018
comment
กล่าวคือไม่มีค่าคุณสมบัติในประเภทองค์ประกอบ - person Heena; 02.03.2018
comment
ฉันไม่เห็นองค์ประกอบอินเทอร์เฟซในโค้ดของคุณ stackblitz.com/angular/ อย่างที่คุณเห็น คุณต้องกำหนดโครงสร้างของ Element - person Damien Vitrac; 02.03.2018
comment
ฉันเพิ่งเพิ่ม..องค์ประกอบอินเทอร์เฟซการส่งออก { acc_id: any; ค่า: ใด ๆ ; acc_des: ใด ๆ ; } - person Heena; 02.03.2018
comment
คุณช่วยตรวจสอบคำถามนี้ได้ไหม...stackoverflow.com/questions/49069432/ - person Heena; 02.03.2018