如何绑定2款至一个输入场角? [英] How to bind 2 models to one input field in Angular?

查看:88
本文介绍了如何绑定2款至一个输入场角?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

反正是有,我可以结合两种模式,一个输入字段?假设我有我要在范围内的东西就像两个变量的值输入字段:

 <输入类型=文本模式=sn_number; ID>


解决方案

您不能,但也有一些解决办法。

1。使用ngChange更新其他模型

 <输入类型=文本
       NG-模式=sn_number
       NG-变化=ID = sn_number/>

2。你可以观看模式,而当变化,更新另一个

  $范围。$腕表('sn_number',函数(五){
  $ scope.id = V;
});

您需要还来观察 ID 的变化,如果你想保持同步。

例这里

is there anyway that i can bind two model to one input field ? Suppose I have input field which I want to be the value of two variables in the scope something like:

<input type="text" model="sn_number; id" > 

解决方案

You cannot, but there are some workarounds.

1. Use ngChange to update the other model

<input type="text" 
       ng-model="sn_number" 
       ng-change="id=sn_number"/> 

2. You could watch a model, and when in changes, update another

$scope.$watch('sn_number', function(v){
  $scope.id = v;
});

You would need to watch also for changes in id if you want to keep them in sync.

Example here

这篇关于如何绑定2款至一个输入场角?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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