Javascript 角度-ng模型值指定给另一个ng模型
我正在使用angularJS 我有两部分Javascript 角度-ng模型值指定给另一个ng模型,javascript,angularjs,Javascript,Angularjs,我正在使用angularJS 我有两部分 通讯地址 永久地址 每个部分都有文本框作为相同的字段 我还有一个复选框。一旦选中复选框,表示通信地址被分配给永久地址 我在这里附上了我的代码。我试过它不起作用。有人能建议如何实施这一点吗 角度模块('ExampleApp',[]) .controller('firstCtrl',函数($scope,$filter){ $scope.localAddress={}; $scope.permanentAddress={}; $scope.address={
通讯地址
门号
街头
位置
城市
地区
陈述
国家
Pin码
联系电话
永久地址
{{address.value}}
(与通讯地址相同)
门号
街头
位置
城市
地区
陈述
国家
Pin码
联系电话
是否执行此更改
<input type="checkbox" ng-model="address.value" ng-change="copyCommToPerm()">
我更新了你的代码,请检查。它可以按照你的要求正常工作 角度模块('ExampleApp',[]) .controller('firstCtrl',函数($scope,$filter){ $scope.localAddress={}; $scope.permanentAddress={}; $scope.address={ 值:false }; $scope.IsAddressClone=function() { if($scope.address.value){ $scope.permanentAddress=Object.assign({},$scope.localAddress); } 其他的 { $scope.permanentAddress={}; } } });代码>
通讯地址
门号
街头
位置
城市
地区
陈述
国家
Pin码
联系电话
永久地址
{{address.value}}
(与通讯地址相同)
门号
街头
位置
城市
地区
陈述
国家
Pin码
联系电话
您可以进行以下更改:
<input type="checkbox" ng-model="address.value" ng-change="address.value ? setSame():setDiff()">
您的观点存在许多问题:
minlenght="10"
应更改为ng minlenght=“10”
以下内容同样适用于maxlength
和wh
$scope.setSame = function(){
//fired when checkbox is checked
$scope.permanentAddress = angular.copy($scope.localAddress);
}
$scope.setDiff = function(){
//fired when checkbox is unchecked, reset the permanent address
$scope.permanentAddress = {};
}
minlenght="10"
$scope.IsAddressClone = function() {
if ($scope.address.value) {
$scope.permanentAddress = angular.copy($scope.localAddress);
}
}
$scope.$watchCollection('localAddress', function(nv, ov) {
if (nv !== ov) {
$scope.IsAddressClone();
}
})