ionic3& angular4遇到未定义的提供商!通常这意味着您具有循环依赖关系

时间:2017-10-17 02:10:00

标签: angular ionic3

我是一个新的离子和角度。我写的代码:

task.service.ts:

import { Injectable } from '@angular/core';

import { Task } from '../model/task';
import { Dummy } from '../data/dummy';

@Injectable()
export class Taskservice {

  getAllTaskByUser(uid: String): Task[]{
    console.log('getAllTaskByUser');

    return TASKS;
  }
}

task.ts

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';

import { Task } from '../../model/task'
import { TaskService } from '../../service/task.service'


@IonicPage()
@Component({
  selector: 'page-task',
  templateUrl: 'task.html',
  providers: [TaskService]
})
export class TaskPage {
  searchQuery: string = '';
  taskList: string = "notStarted";
  allTasks: Task[];
  notStartedItems: String[];
  startedItems: String[];
  completedItems: String[];
  tab1: any;

  constructor(public navCtrl: NavController, public navParams: NavParams, private taskService: TaskService) {
    this.getAllItems();

    // tab1 =
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad TaskPage');
  }

  getAllItems() {
    this.allTasks = this.taskService.getAllTaskByUser('')
  }

  searchItems(ev: any) {
    // set val to the value of the searchbar
    let val = ev.target.value;

    // if the value is an empty string don't filter the items
    if (val && val.trim() != '') {
      this.allTasks = this.allTasks.filter((item) => {
        return (item.name.toLowerCase().indexOf(val.toLowerCase()) > -1);
      })
    }
  }

}

task.ts:

export class task {
  id: String;
  taskname: String;
  state: String;
}

dummy.ts:

import { Task } from '../model/task';

export const TASKS: Task[] = [{ "id": "1", "taskname": "作业001", "state": "未完成" },

{ "id": "2", "taskname": "作业002", "state": "已完成" },

{ "id": "3", "taskname": "作业003", "state": "未开始" },

{ "id": "4", "taskname": "作业004", "state": "未开始" }];

开始发球后,我收到了错误信息 "运行时错误 遇到未定义的提供商!通常这意味着您有一个循环依赖(可能是由于使用'桶' index.ts文件引起的。"

有人可以帮忙吗? 我很抱歉如果发布这个错误,也是stackoverflow中的新内容。

1 个答案:

答案 0 :(得分:2)

您的课程TaskService实际拼写为Taskservice

@Injectable()
export class Taskservice <-- lower case 's'{

  getAllTaskByUser(uid: String): Task[]{
    console.log('getAllTaskByUser');

    return TASKS;
  }
}

@Component({
  selector: 'page-task',
  templateUrl: 'task.html',
  providers: [TaskService] <-- Capital 'S'
})