Created
April 20, 2014 03:45
-
-
Save izumin5210/11104465 to your computer and use it in GitHub Desktop.
【AngularJS】改行を有効にするためのフィルタ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app = angular.module 'MyApplication' | |
app.filter 'noHTML', -> | |
(text) -> text.replace(/</g, '<').replace(/>/g, '>').replace(/&/, '&') if text? | |
app.filter 'newlines', ($sce) -> | |
(text) -> $sce.trustAsHtml(if text? then text.replace(/\n/g, '<br />') else '') | |
app.controller 'testCtrl', ($scope) -> | |
$scope.iroha = 'いろはにほへと ちりぬるを\nわかよたれそ つねならむ\nうゐのおくやま けふこえて\nあさきゆめみし ゑひもせす' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p ng-controller="testCtrl" ng-bind-html="iroha | noHTML | newlines"></p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
4行目がこれな気がしますよ。