我有以下代码(见下文)。当我单击按钮并选择文件时,视图中的data.myVar保持不变。 (不知何故,我确实看到$scope.data.myVar
在步进控制器时正确更新了。为什么会这样?
html摘录(它位于以下控制器下):
{{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';
}
}]);
答案 0 :(得分:2)
使用指令而不是hacky。这是一个类似的问题: AngularJs: How to check for changes in file input fields?