Проблема, чтобы иметь эллипсы в несколько строк, используя угловые 7

Небольшой пример библиотеки, которая использует localStorage для отслеживания полученных сообщений от контактов:

// This class is supposed to be used to keep a track of received message per contacts.
// You have only four methods:

// 1 - Tells you if you can use this library or not...
function isLocalStorageSupported(){
    if(typeof(Storage) !== "undefined" && window['localStorage'] != null ) {
         return true;
     } else {
         return false;
     }
 }

// 2 - Give the list of contacts, a contact is created when you store the first message
 function getContacts(){
    var result = new Array();
    for ( var i = 0, len = localStorage.length; i < len; ++i ) {
        result.push(localStorage.key(i));
    }
    return result;
 }

 // 3 - store a message for a contact
 function storeMessage(contact, message){
    var allMessages;
    var currentMessages = localStorage.getItem(contact);
    if(currentMessages == null){
        var newList = new Array();
        newList.push(message);
        currentMessages = JSON.stringify(newList);
    }
    else
    {
        var currentList =JSON.parse(currentMessages);
        currentList.push(message);
        currentMessages = JSON.stringify(currentList);
    }
    localStorage.setItem(contact, currentMessages);
 }

 // 4 - read the messages of a contact
 function readMessages(contact){

    var result = new Array();
    var currentMessages = localStorage.getItem(contact);

    if(currentMessages != null){
        result =JSON.parse(currentMessages);
    }
    return result;
 }
0
задан Pavan Shukla 20 March 2019 в 12:18
поделиться

2 ответа

Вы можете обрезать текст следующим образом (используя трубу среза)

{{ (str.length>6)? (str | slice:0:6)+'..':(str) }}
0
ответ дан Valdemar26 20 March 2019 в 12:18
поделиться

Я лично использую библиотеку ng-truncate, чтобы добиться этого, зачем изобретать велосипед. https://github.com/yellowspot/ng2-truncate

Пример:

Импортируйте его в свой модуль

import { TruncateModule } from "@yellowspot/ng-truncate";

@NgModule({
  declarations: [
  ...
  ],
  imports: [
     TruncateModule,
  ]
});

По вашему мнению Вы можете сделать

<div class="test" [innerHtml]="anchor | truncate:200"></div>
0
ответ дан Jamie Rees 20 March 2019 в 12:18
поделиться
Другие вопросы по тегам:

Похожие вопросы: