Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Angular Js中自定义双向数据绑定_Javascript_Angularjs_Data Binding - Fatal编程技术网

Javascript 如何在Angular Js中自定义双向数据绑定

Javascript 如何在Angular Js中自定义双向数据绑定,javascript,angularjs,data-binding,Javascript,Angularjs,Data Binding,HTML: 数据: 当我在下拉列表中选择devicename时,文本框中将显示相应的宽度。它工作得很好。但当我在文本框中更改值时,我不想更改原始值 简单地说,我想在文本框中显示值并进行编辑。但是我不想存储这个值 将ng change=“updateDeviceWidthTextbox()”添加到选择,将输入字段的模型更改为类似ng model=“deviceWidthTextbox”的格式,并在控制器中实现以下功能: $scope.updateDeviceWidthTextbox = fun

HTML:


数据:

当我在下拉列表中选择devicename时,文本框中将显示相应的宽度。它工作得很好。但当我在文本框中更改值时,我不想更改原始值

简单地说,我想在文本框中显示值并进行编辑。但是我不想存储这个值

ng change=“updateDeviceWidthTextbox()”
添加到选择,将输入字段的模型更改为类似
ng model=“deviceWidthTextbox”
的格式,并在控制器中实现以下功能:

$scope.updateDeviceWidthTextbox = function() {
     $scope.deviceWidthTextbox = deviceList[selectedDeviceID].width;
};

可能是我没有正确地理解你。希望我能帮助你

<select ng-change="changed(selectedDeviceID)" data-ng-options="o.id as o.device for o in deviceList" data-ng-model="selectedDeviceID"></select>
<input type="text" id="deviceWidth" ng-model="inputText" placeholder="width"/>
<select ng-change="changed(selectedDeviceID)" data-ng-options="o.id as o.device for o in deviceList" data-ng-model="selectedDeviceID"></select>
<input type="text" id="deviceWidth" ng-model="inputText" placeholder="width"/>
$scope.changed = function (selectedDeviceID) {
    $scope.inputText = $scope.deviceList[selectedDeviceID].width
});