I am developing an AngularJS application same like how we post answers and questions on stackoverflow and we get live preview of our answers or question just below the texta
Thats because newlines in the textarea are not HTML line breaks. You need to replace them with something like this:
$(document).ready(function() {
var pad = $('#pad');
var board = $('#board');
pad.keypress(function(event) {
board.html(pad.val().replace(/\r?\n/g, '<br />'));
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea id="pad"></textarea>
<div id="board"></div>