集成angularjs服务

时间:2019-07-10 11:27:58

标签: angularjs ionic-framework

您好,我遇到问题了,我创建了票务服务。此文件,我尝试将其添加到home.ts文件,但它给我一个错误

tickerServices.ts

import { Injectable } from '@angular/core';
@Injectable({
  providedIn: 'root',
})
export class TicketService{
  result:any;
constructor(public http: HttpClient) { }
getTicket(){
  var CronJob = require('cron').CronJob;
  var id=this.formulaire.id;
  new CronJob('* * * * * *', function(){
    const http = require('http');
    console.log('You will see this message every second');
    /* this.url+'/'*/
    http.get('http://localhost:8888/'+id+'/notif', (resp) => {
    let data = '';

    // A chunk of data has been recieved.
    resp.on('data', (chunk) => {
      data += chunk;
      this.resulta=data;
    });
    // The whole response has been received. Print out the result.
    resp.on('end', () => {
      console.log(data);
    });

  }).on("error", (err) => {
    console.log("Error: " + err.message);
  });

  }, null, true, 'America/Los_Angeles');

}
}

home.ts

import {Component} from "@angular/core";
import {NavController, PopoverController,NavParams} from "ionic-angular";
import { HttpClient } from '@angular/common/http';
import { TicketService } from '../services/ticketservice'
import 'rxjs/add/operator/map';
@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
public search = {
    date: new Date().toISOString()
  }
  constructor(public nav: NavController,public http: HttpClient,public popoverCtrl: PopoverController ,public tikSer:TicketService) {
}}

当我测试它时,他给了我未定义的“ .. / services / ticketservice”

my files

1 个答案:

答案 0 :(得分:2)

像这样添加它

import { TicketService } from '../../services/ticketservice'