src / app / app.component.ts(72,69)中的错误:错误TS1005:“,”预期

时间:2018-09-07 07:17:26

标签: angular

正在尝试用角度6尝试从app.component.ts中调用service.ts文件的方法

play(){
    this.uploadService.playClientRecord(this.result1).subscribe(data:any=>{
        console.log('method called');
    });
    console.log('started Playing records');
    this.isPlayed=true;
}

service.ts

playClientRecord(model: any){
    console.log('MOD'+model);
    const options = {headers: {'Content-Type': 'application/json'}};
    this.http.post('http://10.71.9.178:8080/replayservice/uploadFile', model, options).map(response=>response.json()).subscribe(
        event => console.info(JSON.stringify(t))
    );
}

在编译代码时出错

  

日期:2018-09-07T07:12:53.215Z-哈希:a4e278d9bdebc1d005c6-时间:   302ms 5个不变的块i?wdm ?:成功编译。我?wdm?   编译中... 10%的构建模块0/1模块1个活动的._code   base \ client \ src \ app \ app.module.tsERROR在   src / app / app.component.ts(72,69):错误TS1005:“,”预期。

     

日期:2018-09-07T07:14:57.482Z-哈希:192e0278be7a3932111d-时间:   177ms 4个未更改的块chunk {main} main.js,main.js.map(main)18.1   kB [initial] [renderd] i?wdm ?:已成功编译。

1 个答案:

答案 0 :(得分:0)

尝试这样:

  

使用(data:any)代替 data:any   组件:

import { UploadFileService } from './upload-file.service';
import { Component } from '@angular/core';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  providers: [UploadFileService]
})
export class AppComponent {

  constructor(private uploadService: UploadFileService) { }

  play() {
    this.uploadService.playClientRecord(this.result1).subscribe((data: any) => {
      console.log(data);
    });
    console.log('started Playing records');
  }
}

service.ts:

import { Injectable } from '@angular/core';
import { HttpClient, HttpRequest, HttpEvent } from '@angular/common/http';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

@Injectable()
export class UploadFileService {
  constructor(private http: HttpClient) { }
  playClientRecord(model: any): Observable<any> {
    const options = { headers: { 'Content-Type': 'application/json' } };
    return this.http.post('http://10.71.9.178:8080/replayservice/establishsession ', model, options);
  }
}

在app.module.ts中:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { UploadFileService } from './upload-file.service'
import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    HttpClientModule
  ],
  providers: [UploadFileService],
  bootstrap: [AppComponent]
})
export class AppModule { }