无法在nativescript的console.log()中看到值

时间:2019-02-21 19:13:57

标签: nativescript angular2-nativescript nativescript-angular

我有一个包含数组的js文件! js文件就是这样

export const appointments = [
{
  "taskID": 9018929,
  "resource_ID": 1,
  "title": "KNDL Thatcham",
  "description": "<Non-Selected>\r\n10:00 - 18:00",
  "startTime": "2018-12-28T00:00:00",
  "endTime": "2018-12-28T23:59:00",
  "statusColour": "#DFDFDF",
  "clientColour": "#FFFDD7"
}]

我已将此js文件导入service.ts。而且,这个约会.js不会显示在console.log中。

import { Injectable } from '@angular/core';
        import { appointments } from '../appointments';
        import { Color } from "tns-core-modules/color";
        // >> angular-calendar-require
        import { CalendarEvent } from 'nativescript-ui-calendar';


        @Injectable({
        providedIn: 'root'
        })


    export class CalendarService {

      constructor() { 
      //var a="test test etsdhsakdsakd dsddssdsd";
      console.log(appointments);
    } 

这是我要导入service.ts的组件

import { Component, OnInit } from '@angular/core';

import { CalendarService } from "./service/calendar.service";
import { RadCalendar, CalendarEvent, CalendarSelectionEventData } from "nativescript-ui-calendar";
@Component({
  selector: 'ns-calendar',
  templateUrl: './calendar.component.html',
  styleUrls: ['./calendar.component.css'],
  moduleId: module.id,
  providers: [CalendarService]
})
export class CalendarComponent implements OnInit {
}

1 个答案:

答案 0 :(得分:1)

您需要将CalendarService类型的private calendarService参数添加到构造函数中。

当Angular创建CalendarComponent时,Dependency Injection系统将calendarService参数设置为CalendarService的单例实例。

导出类CalendarComponent实现了OnInit { 构造函数(calendarService:CalendarService){}

}