V
V
Vitaliy Rokossovyk2016-04-26 20:28:37
css
Vitaliy Rokossovyk, 2016-04-26 20:28:37

How to load templates in AngularJS?

Hello.
I am writing a chat using AngularJS in the client.
The appearance of messages in the chat is implemented through $compile. That is, in the Angular code there is a recorded HTML code, it is not very convenient to read this + there is a problem when HTML code is sent to the chat, which is not strange.
Question: what and how to use in order to load a ready-made template with variables for each message, and so that there would be no such problems with the HTML code that users send?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2016-04-26
@powerchord

The appearance of messages in the chat is implemented via $compile.

What for? Much more practical is to use the good old ngRepeat. So you can then screw some virtual scrolls, etc. The division of responsibility is shorter.
And what you describe is jquery-style.
To protect against XSS, just use $sanitize.

_
_ _, 2016-04-26
@AMar4enko

Use $sanitize to remove potentially dangerous constructs from bare html.
It's hard for me to imagine why you use $compile with an inline template to display messages.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question