如何禁用的AngularJS投入微调? [英] How to disable trimming of inputs in AngularJS?
问题描述
我发现了一些奇怪的现象:在默认情况下角修剪模型值。快速谷歌搜索不帮我解决这个问题。我发现 NG-没有修剪
指令提案, NG-修剪
等。但没有任何工程。
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.
我提供了一个小片段,重新presents下面这个问题。
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.
我添加了一个textarea的是同步与模型文本
。但它并不适合观看的时候添加新的尾随空格或打破行至新的反应。
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斌片断。
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屋!