Angularjs to angular6

Hello I have below function in angularjs which uses prototype inheritance.

 function Conversation()  {
            this.currentBox = 1;
            this.internalId = null;
            this.subject = null;
            this.unreadMessageCount = 0;
            this.updateDate = new Date();
            this.updatedBy = null;
            this.messages = [];
            this.participants = {};
            this.isComplete = false;
        }
        Conversation.prototype.setupFromConversation = function (conversation) {
            this.currentBox = conversation.currentBox ||  null;
            this.internalId = conversation.internalId ||  null;
            this.subject = conversation.subject ||  null;
            this.unreadMessageCount = conversation.unreadMessageCount ||  null;
            this.updateDate = conversation.updateDate ||  null;
            this.updatedBy = conversation.updatedBy.toLowerCase() ||  null;
            this.messages = conversation.messages ||  [];
            this.participants = {};
            this.addParticipants(conversation.participants);
}

I want to have function in angular 6 application, please remember that this is seperate file in angularjs application and I would like to have same thing where I can use this function in angular 6 application.

Why cant you create a class,

class Conversation {
  currentBox = 1;
  internalId = null;
  subject = null;
  unreadMessageCount = 0;
  updateDate = new Date();
  updatedBy = null;
  messages = [];
  participants = {};
  isComplete = false;
  setupFromConversation = function (conversation) {
    this.currentBox = conversation.currentBox ||  null;
    this.internalId = conversation.internalId ||  null;
    this.subject = conversation.subject ||  null;
    this.unreadMessageCount = conversation.unreadMessageCount ||  null;
    this.updateDate = conversation.updateDate ||  null;
    this.updatedBy = conversation.updatedBy.toLowerCase() ||  null;
    this.messages = conversation.messages ||  [];
    this.participants = {};
    this.addParticipants(conversation.participants);
  }
};

later u can export it or use it in any file in angular application.

1 Like