如何在 Angular/Ionic 应用程序中使用服务内部的多个模型?

用户9847788

在我的 Angular/Ionic 应用程序中,我试图在下面创建 2 个模型(对话和消息),并在我的对话服务中使用它们。

当用户登录时,他们应该看到他们之前与机械师(也是用户,但具有不同的userType)的对话列表

当他们单击某个对话时,他们将被带到 Conversation_Detail 屏幕,该屏幕显示属于该对话的所有消息。

在 Conversation_Detail 上,用户和机械师可以发送新消息。这些新消息将添加到现有对话中。

这是我拥有的模型:

conversation.model.ts

export class Conversation {
    constructor(
        public id: string,
        public userId: string,
        public mechanicId: string,
        public messages: Array<string>,
    ) { }
}

message.model.ts

export class Message {
    constructor(
        public id: string,
        public text: string,
        public userId: string,
        timestamp: string
    ) { }
}

正如您在上面看到的,我正在尝试将多个消息连接到一个对话。

这是我试图创建一个虚拟对话的地方:

Conversations.service.ts

private _conversations: Conversation[] = [
    new Conversation('c1', 'abc1', 'def2', ['Hi', 'What is your issue?'])
  ];

有人可以告诉我如何正确链接对话和消息,以便我可以在对话服务中使用它们吗?

用户9847788

我已经尝试修复它,这是我想出的,目前正在测试它,如果它正常工作,将更新:

conversations.service.ts

private _conversations: Conversation[] = [
    new Conversation(
      'c1',
      'abc1',
      'def2',
      [new Message('mess1', 'Test message', 'abc1', '01/01/2020')])
  ];

conversation.model.ts

import { Message } from './message.model';

export class Conversation {
    constructor(
        public id: string,
        public userId: string,
        public mechanicId: string,
        public messages: Message[],
    ) { }
}

message.model.ts

export class Message {
    constructor(
        public id: string,
        public text: string,
        public userId: string,
        timestamp: string
    ) { }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

地名Web服务:如何在Android应用程序中使用?

如何在未附加到应用程序模型的类中使用eclipse 4 DI?

应用程序如何在.NET或Java中使用多个内核或CPU?

如何在Java应用程序中使用Akka Actors?

如何在Golang应用程序中使用多个JSON参数创建SQL查询?

如何在单个带有Spring Cloud Security Oauth2的Spring引导应用程序中使用多个Oauth2 SSO服务器?

如何在多个应用程序(AccountAuthenticator,sharedUserId,Google Play应用程序签名)中使用一个帐户?

如何在应用程序模型中使用FieldValue.serverTimestamp

当应用程序中使用多个该类型的列表时,如何在模型中保留自定义对象序列属性

托管多个实例时如何在C#Web API应用程序中使用OAuth

如何在共享数据库中使用多个spring-data应用程序

如何在单个Flask应用程序中使用Plotly-Dash创建多个Dashoards?

如何在一个应用程序中使用多个openGL状态?

如何在.net核心应用程序中使用Powershell启动Windows服务?

如何在Websocket symfony应用程序的服务中使用实体,表单,控制器

如何在同一个cherrypy应用程序中使用多个调度程序?

如何在SailsJS应用程序中使用多个布局?

如何在外部asp.net应用程序中使用Dynamics AX Web服务

如何在Rails应用程序的ruby中使用postgresql“内部联接”?

如何在Windows 7的多个应用程序中使用单个MIDI控制器?

如何在Symfony2应用程序中使用现有的Web服务?

如何在MVC应用程序中使用Moq和Nunit模拟服务-防止为空

如何在不带X的Linux服务器中使用GUI打开Mono应用程序?

如何在 Spring 应用程序中使用多个控制器?

如何在 WCF 服务应用程序中使用 Microsoft.SqlServer.Types

如何在整个 Angular 应用程序中使用实例服务?

如何在 PopSQL 应用程序中使用 DELIMITER 语句?

如何在 Blazor 服务器应用程序中使用 Bootstrap-select

如何在我的 Flutter 应用程序中使用我的数据模型?