Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/397.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 Can';t更新函数angularjs中的变量值_Javascript_Html_Css_Angularjs - Fatal编程技术网

Javascript Can';t更新函数angularjs中的变量值

Javascript Can';t更新函数angularjs中的变量值,javascript,html,css,angularjs,Javascript,Html,Css,Angularjs,您好,开发人员请帮助,动态更新值在传递html标记的angularjs控制器中运行良好。但当我在函数内部(控制器内部)使用范围变量时 更新功能外的值时工作正常: var-app=angular.module('previewApp',[]); app.controller('previewCtrl',函数($scope){ var$=jQuery; var targetValue=0; $scope.w=targetValue; }); 传递到html span标记: 但每当输入事件触发器

您好,开发人员请帮助,动态更新值在传递html标记的angularjs控制器中运行良好。但当我在函数内部(控制器内部)使用范围变量时

更新功能外的值时工作正常:

var-app=angular.module('previewApp',[]);
app.controller('previewCtrl',函数($scope){
var$=jQuery;
var targetValue=0;
$scope.w=targetValue;
});
传递到html span标记:


但每当输入事件触发器值没有在函数内部动态更新时,我就会使用jQuery获取值,在控制台中,值会完全更新(console.log('Width'+targetValue);),但在html标记中不会:

函数onChangeWidth(事件){
if(event.which!=8&&event.which!=0&&event.which<48 | | event.which>57)){
isProcess=false;
}
const targetValue=$(this).closest('.gfield').find('input').val();
//$scope.width=;
$scope.w=函数(){
返回目标值;
};
$scope.docPPIWidth=ppi*+targetValue;
console.log('Width'+targetValue);
$scope.w=targetValue;//更新w在函数内部不起作用
}
函数onChangeHeight(事件){
const targetValueH=$(this).closest('.gfield').find('input').val();
if(event.which!=8&&event.which!=0&&event.which<48 | | event.which>57)){
var isProcess=false;
}
$scope.docPPIHeight=ppi*targetValueH;
console.log('Height'+targetValueH);
}
$('.width\u check input')。on('change click',onChangeWidth);
$('.height\u check input')。在('change click',onchange height)上;

我给你的第一个建议是开始考虑如何防止JQuery和AngularJS的混合,因为最终你会遇到“bug启示录”。 我认为在您的情况下,Angular不知道JQuery触发了一个事件,因此摘要循环不会自动触发。 同样,此解决方案可以在特定情况下帮助您,但它实际上不是一个好的做法:

$scope.w = targetValue;
$scope.$digest();
更改scope变量后,让Angular知道它必须通过添加
$scope.$digest()
来触发摘要循环以刷新视图数据。此函数将仅检查此组件及其子作用域数据。如果您需要检查整个应用程序,请使用
$rootScope.$digest()
(从性能角度看,这是一个非常糟糕的决定)