[英]How to combine two inputs into one value and bind?
I use 2 Inputs to define an age. 我使用2个输入来定义年龄。 Both values should be passed to a new input which is alread binded to rule.data . 这两个值都应传递到一个新输入,该输入已绑定到rule.data 。 Is that possible? 那可能吗? I'm new with angularjs and probably I have a flaw. 我是angularjs的新手,可能有一个缺陷。 Thanks for your tips 谢谢你的提示
HTML 的HTML
<input type="number" class="form-control input-sm" min="1" max="110" ng-model="age.from"/>
<input type="number" class="form-control input-sm" min="1" max="110" ng-model="age.to"/>
<input type="text" class="form-control input-sm" ng-model="rule.data" value="between {{age.from}} and {{age.to}}" />
I do not really understand why you want to use an <input>
to format a text with the values of min and max. 我不太了解为什么要使用<input>
格式化具有min和max值的文本。
You would rather do this, no ? 您宁愿这样做,不是吗?
<input type="number" class="form-control input-sm" min="1" max="110" ng-model="age.from"/>
<input type="number" class="form-control input-sm" min="1" max="110" ng-mdodel="age.to"/>
<span>between {{age.from}} and {{age.to}}</span>
Does this work for you ? 这对您有用吗?
If the string is just a placeholder for the user age value, you should do this instead : 如果字符串只是用户年龄值的占位符,则应改为:
<input type="number" class="form-control input-sm" min="1" max="110" ng-model="age.from"/>
<input type="number" class="form-control input-sm" min="1" max="110" ng-mdodel="age.to"/>
<input type="text" class="form-control input-sm" ng-model="rule.data" placeholder="between {{age.from}} and {{age.to}}" />
If you need to get the final string into the model, you can do something like this then: 如果需要将最终字符串输入模型,则可以执行以下操作:
<input type="number" class="form-control input-sm" min="1" max="110" ng-model="age.from"/>
<input type="number" class="form-control input-sm" min="1" max="110" ng-mdodel="age.to"/>
<input type="text" class="form-control input-sm" ng-model="rule.data" ng-init="rule.data = 'between ' + age.from + ' and ' + age.to" />
(I assume you do not have a controller to initialize the model properly. If you do, then just add this kind of line inside : $scope.rule.data = 'between ' + $scope.age.from + ' and ' + $scope.age.to;
. it should do the trick.) (我假设您没有控制器来正确初始化模型。如果您这样做,则只需在其中添加以下行: $scope.rule.data = 'between ' + $scope.age.from + ' and ' + $scope.age.to;
can vary with many solutions, you can add a custom filter at third combined result , 可能因许多解决方案而异,您可以在第三个合并结果中添加自定义过滤器,
<input type="text" class="form-control input-sm" ng-model="rule.data | customFilter:age.from:age.to" value="between {{age.from}} and {{age.to}}" />
app.filter('customFilter',function(){
return function(input ,fromage,toage){
//your code for between
return //your calculated age
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.