【发布时间】:2021-04-03 10:24:40
【问题描述】:
您好开发人员请帮助,在传递 html 标记的 angularjs 控制器中动态更新值工作完美。但是当我在函数内(控制器内)使用范围变量时。
在函数外更新值时完美运行:
var app = angular.module('previewApp', []);
app.controller('previewCtrl', function ($scope) {
var $ = jQuery;
var targetValue = 0;
$scope.w = targetValue;
});
传递给 html span 标签:
<span style="width:{{w}}px;height:{{h}}px; background-color: white" class="item-inner">
但是每当输入事件触发值没有在函数内部动态更新时,我都会使用 jQuery 获得价值,在控制台中的值正在完美更新 (console.log('Width ' + targetValue);) 但不在 html 标记中:
function onChangeWidth(event) {
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 = function () {
return targetValue;
};
$scope.docPPIWidth = ppi * +targetValue;
console.log('Width ' + targetValue);
$scope.w = targetValue; //updating w didn't work inside function
}
function onChangeHeight(event) {
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_check input').on('change click', onChangeWidth);
$('.height_check input').on('change click', onChangeHeight);
【问题讨论】:
标签: javascript html css angularjs