Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 无法使用注入服务_Typescript_Angular - Fatal编程技术网

Typescript 无法使用注入服务

Typescript 无法使用注入服务,typescript,angular,Typescript,Angular,将简单服务导入login.component.ts:` import { Component } from '@angular/core'; import {TestService} from '../login/TestService'; @Component({ providers: [TestService], templateUrl: './app/login/loginTemplate.html' }) export class loginComponent {

将简单服务导入login.component.ts:`

import { Component } from '@angular/core';
import {TestService} from '../login/TestService';

@Component({
    providers: [TestService],
    templateUrl: './app/login/loginTemplate.html'
})
export class loginComponent  {
    constructor(testService: TestService){}

    sendLoginRequest() {
        this.testService.writeLine();
    }
}
这是TestService文件

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

@Injectable ()
export class TestService {
    constructor () {}

    writeLine () {
         return console.log("works from service");
    }
}

对于这种简短形式,需要使用
私有
公共

constructor(private testService: TestService){}
如果没有此访问修饰符,则需要执行以下操作

testService;TestService;
constructor(testService: TestService){
  this.testService = testService;
}

错误是什么?真正的问题是什么?