2017-09-04 95 views
0

我想創建一個角度爲2的聊天應用程序,我需要在輸入字段中顯示Emojis,但html不支持輸入字段中的圖像。
也是我試過這種方法,但沒有奏效:角度2輸入與圖像支持

<div contenteditable="true" 
    [innerHtml]="msgText" 
    class="form-control" 
    (keyup)="enable_disable_sendBtn()" 
    (keypress)="handle_enter_key($event)" 
    #messageBox 
    (input)="msgText = $event.target.innerText"> 
</div> 

我已經試過this但不是我從tslint了錯誤,並說:use @HostListener Or @HostBinding instead of host
任何人都可以幫助我在文本輸入中顯示emjis嗎?

+0

「但沒有工作」是不夠的信息。預期的行爲是什麼?什麼是實際行爲?任何錯誤消息? –

+0

也許你想使用https://www.emojione.com/或類似的 –

+0

@GünterZöchbauer我期望顯示圖像,它顯示,但問題是當我試圖寫'amir'它寫'rima'所以問題是無論何時按下某個鍵(或者鍵入或按鍵,我都不知道問題是什麼)時,插入符號會轉到第一個輸入 – amirsa00

回答

0

最後我找到了一個解決方案。解決方案是單向綁定,導致用戶在contenteditable中寫入內容,而當我想要例如:何時發送內容時,我只需要獲取innerHTML
也當我想添加一個圖像的內容,只需添加到contenteditable,當我需要發送(或類似的東西)我得到innerHTML

<div contenteditable="true" 
    class="form-control" 
    id="messageBox" 
    #messageBox 
    (keydown.enter)="handle_enter_key($event)" 
    (input)="handleMessageBoxInput($event)"> 
</div>