typescript 如何使用服务,请参阅评论。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了typescript 如何使用服务,请参阅评论。相关的知识,希望对你有一定的参考价值。

// We have to define the constructor that angular is going to use when instanciate the class
// We have to define constructor, providers, import the class and use it

import { LoggingService } from './../logging.service'; // Import the service
import { Component, EventEmitter, Output } from '@angular/core';

@Component({
  selector: 'app-new-account',
  templateUrl: './new-account.component.html',
  styleUrls: ['./new-account.component.css'],
  providers: [LoggingService] // We have to inform angular about our dependency
})
export class NewAccountComponent {
  @Output() accountAdded = new EventEmitter<{name: string, status: string}>();

  // The type of the parameter must be the class of the service
  constructor(private loggingService: LoggingService) {}

  onCreateAccount(accountName: string, accountStatus: string) {
    this.accountAdded.emit({
      name: accountName,
      status: accountStatus
    });
    this.loggingService.logStatusChange(accountStatus); // Use the method of the service
  }
}

以上是关于typescript 如何使用服务,请参阅评论。的主要内容,如果未能解决你的问题,请参考以下文章

如何将我们的应用程序重新上传到appstore

ICE 失败,您的 TURN 服务器似乎已损坏,有关详细信息,请参阅 about:webrtc

服务器在处理请求时遇到错误。有关更多详细信息,请参阅服务器日志

如何防止 ServerXMLHTTP 自动跟随重定向(HTTP 303 请参阅其他响应)?

是否可以将 yarn-pnp 与 typescript/vscode 一起使用?

python 我的文章中使用Python和Flask微框架构建RESTful Web服务的代码。请参阅此处的文章:http://blog.miguel