[英]Access variable by string in AngularJS
我想訪問和更新變量的狀態。
function valueChange(sourceVariable, targetVariable, sourceUnit) {
$scope[targetVariable] = measure($scope[sourceVariable] + sourceUnit + ".").kilograms();
});
只要在輸入字段中輸入某些內容(在選項卡上),就會調用此函數。 但是問題是,綁定到$ scope [targetVariable]的輸入字段中的值只有在輸入框內單擊后才會更新。
PS:如果我以常規方式使用變量,則效果很好。
您可能需要在$scope.$apply
變量:
function valueChange(sourceVariable, targetVariable, sourceUnit) {
$scope.$apply(function() {
$scope[targetVariable] = measure($scope[sourceVariable] + sourceUnit + ".").kilograms();
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.