为什么这个角度JS过滤去掉空格? [英] Why is this Angular JS filter removing spaces?
问题描述
我在做一个小的应用程序来学习角,并取得了文本处理自定义过滤器。一切都在的情况下工作正常,只是当我的输出文本有多个空格,这些都会自动减少到一个单一的空间,这是我不想要的。这个问题是不是在函数我定义了,因为我日志的输出,这没有问题。
I'm making a tiny app to learn Angular, and have made a custom filter for text processing. Everything is working fine, except that in cases when my output text has multiple spaces, these get automatically reduced to a single space, which I don't want. The issue is not in the function I've defined, because I'm logging the output, which does not have the problem.
HTML
<textarea name="textarea" rows="10" cols="50" ng-model="encodeText" placeholder="Type or paste in a message to encode." ></textarea>
<p>Filtered input: {{ encodeText | encode }}</p>
JS:
(function(){
var app = angular.module('myApp', []);
app.filter("encode", function() {
return function(input) {
if (input) {
//text processing
console.log(output);
return output;
}
};
});
这是一个莫尔斯code锻炼。因此,控制台日志输出是:
It is a Morse Code exercise. So console log output is:
.- -... -.-. -.. . ..-.
使用两个空格。在网页上我看到:
With two spaces. On the page I see:
Filtered input: .- -... -.-. -.. . ..-.
我是从谷歌搜索看到的是在textarea的,它没有影响使用NG-修剪=false的唯一的建议。看来修整过滤器本身内发生的事情。是什么原因造成这一点,我怎么关闭呢? code回购
推荐答案
的 P
格式化输出。
尝试:
The p
format your output.
Try:
<pre>{ encodeText | encode }</pre>
这篇关于为什么这个角度JS过滤去掉空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!