代码之家  ›  专栏  ›  技术社区  ›  Sudhir

Angular EventService Priming Scheduler中的问题

  •  0
  • Sudhir  · 技术社区  · 6 年前

    我正在尝试在下面的角度版本中使用素数调度程序。当我尝试为调度程序创建EventService(以下代码)时,系统抛出以下错误

    “TS2304:找不到名称'httpclient'”

    export class EventService {
      constructor(private httpClient: HttpClient) {}
      getEvents() {
          return this.httpClient
          .get('showcase/resources/data/scheduleevents.json')
          .toPromise()
          .then(res => <any[]>res.json().data)
          .then(data => {
            return data;
          });
      }
    }
    

    模块TS:

    import {
      RadioButtonModule,
      KeyFilterModule,
      DialogModule,
      DropdownModule,
      InputTextModule,
      ScheduleModule,
      TabViewModule,
      MessagesModule,
    } from 'primeng/primeng';
    
    import { HttpClientModule } from '@angular/common/http';
    import { HttpModule } from '@angular/http';
    import { Injectable } from '@angular/core';
    

    角度版本: 角度cli:6.0.8 节点:81.3

    角度:6.0.9 -动画,common,编译器,编译器cli,core,表单http, 语言服务、平台浏览器、平台浏览器、动态浏览器、路由器

    我在Priming网站上找到了上面的代码,看起来,这个为Angular2+和HTTP实现的代码在Angular6中有所贬值。 https://www.primefaces.org/primeng/#/schedule

    有人能照到同样的东西吗?任何帮助都非常感谢。

    1 回复  |  直到 6 年前
        1
  •  0
  •   Sudhir    6 年前

    `import { HttpClientModule } from '@angular/common/http'; 
    
    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        ScheduleModule,
        HttpClientModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    

    import { OnInit, Component, ViewEncapsulation, Injectable } from '@angular/core';
    import { ScheduleModule } from 'primeng/schedule';
    import { Http } from '@angular/http';
    
    
    export class EventService {
    
      constructor(private http: Http) { }
    
      getEvents() {
        return this.http.get('showcase/resources/data/scheduleevents.json')
          .toPromise()
          .then(res => <any[]>res.json().data)
          .then(data => data);
      }
    }