gpt4 book ai didi

javascript - onchange 不会改变 AngularJS View 中的 $scope

转载 作者:行者123 更新时间:2023-11-29 21:21:56 25 4
gpt4 key购买 nike

我有以下代码(见下文)。当我单击按钮并选择文件时, View 中的 data.myVar 保持不变。 (不知何故,我确实看到 $scope.data.myVar 在单步执行 Controller 时正确更新)。为什么会这样?

html 摘录(在下面的 Controller 下):

{{data.myVar}}

<input type="file" onchange="angular.element(this).scope().setRuleFile(this)" />

JS:

angular.module('myModule')
.controller('MyCtrl', ['$scope', function ($scope) {

$scope.data = {
myVar: 'init'
};

$scope.setRuleFile = function(element) {
$scope.data.myVar = 'changed';
}

}]);

最佳答案

改用指令比较简单。这是一个类似的问题: AngularJs: How to check for changes in file input fields?

关于javascript - onchange 不会改变 AngularJS View 中的 $scope,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38340690/

25 4 0
文章推荐: javascript - SignalR 错误无法将类型 'System.Threading.Tasks.Task' 隐式转换为 'string'