× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

AngularJS text formatting "on fly" example

Stepan Suvorov
Apr 28, 2015
<pre><code class="language-javascript"> $scope.$watch('textModel', function (textModel) { $scope.textOutput = formatText(textModel); }); function formatText(text) { var output = ''; var answer = text.split(/\n/); for (var i = 0; i &lt; answer.length; i++) { if (answer[i][0] === "!") { output += '&lt;span class="font1"&gt;' + answer[i].slice(1) + '&lt;/span&gt;&lt;br/&gt;' } else { output += '&lt;span class="font2"&gt;' + answer[i] + '&lt;/span&gt;&lt;br/&gt;' } } return output; }</code></pre> <p> </p> <p>http://jsfiddle.net/STEVER/pkp5q88e/</p> <p> </p>
comments powered by Disqus