如何禁用 AngularJS 中的输入修剪? [英] How to disable trimming of inputs in AngularJS?

查看:24
本文介绍了如何禁用 AngularJS 中的输入修剪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了一些奇怪的行为:默认情况下角度修剪模型值.快速谷歌搜索并不能帮助我解决这个问题.我找到了 ng-no-trim 指令提案,ng-trim 等等.但没有任何效果.

I've found some strange behavior: angular trims model values by default. And quick googling doesn't help me to solve this problem. I've found ng-no-trim directive proposals, ng-trim and so on. But nothing works.

我在下面提供了一个小片段来代表这个问题.

I've provided a little snippet that represents this issue below.

function Ctrl($scope) {
  $scope.text='';

  $scope.$watch('text', function (newValue) {
    console.log(newValue);
  });
}

你也可以在这里试试这个片段.

Also you could try this snippet here.

我添加了一个与模型 text 同步的文本区域.但是在添加新的尾随空格或换行到新的空格时,它不会对观看做出反应.

I've added a textarea that is in sync with model text. But it doesn't react for watching when add new trailing spaces or break the line to new one.

我该怎么做才能关闭这种行为?谢谢.

What could I do to turn off this behavior? Thanks.

推荐答案

有问题的指令是 1.1.1 中的新指令;你可以看到它使用 JS Bin 代码段.

The directive in question is new in 1.1.1; you can see it working using JS Bin snippet.

<textarea cols="30" rows="10" ng-model="text" ng-trim="false"></textarea>

这篇关于如何禁用 AngularJS 中的输入修剪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆