Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/435.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 ng模型更新在inupt类型文件的UI中不可见_Javascript_Angularjs - Fatal编程技术网

Javascript ng模型更新在inupt类型文件的UI中不可见

Javascript ng模型更新在inupt类型文件的UI中不可见,javascript,angularjs,Javascript,Angularjs,我正在尝试一个非常简单的例子。我有一个文件字段和文本字段。选择文件后,需要在文本框中更新其值 我的代码如下所示 <input id="selectedFiles" type="text" ng-model="selectedFiles" placeholder="No file(s) chosen"> <input id="file" type="file" name="file" multiple onchange="angular.element(this).scope

我正在尝试一个非常简单的例子。我有一个文件字段和文本字段。选择文件后,需要在文本框中更新其值

我的代码如下所示

<input id="selectedFiles" type="text" ng-model="selectedFiles" placeholder="No file(s) chosen">

<input id="file" type="file" name="file" multiple  onchange="angular.element(this).scope().fileChange()">
我正在更新onchange中的值模型值,但在UI中它并没有反映出来,尽管输入是通过slectedFiles变量绑定的


我应该怎么做才能使值反映在UI中?

您必须使用对$scope.$apply的调用来包装fileChange函数的主体。Angular将不会测试模型是否已更改

$scope.selectedFiles = "";
$scope.fileChange = function () {
    $scope.$apply(function() {
        file = document.getElementById("file");
        $scope.selectedFiles = file.value;
    });
}

您必须使用对$scope.$apply的调用来包装fileChange函数的主体。Angular将不会测试模型是否已更改

$scope.selectedFiles = "";
$scope.fileChange = function () {
    $scope.$apply(function() {
        file = document.getElementById("file");
        $scope.selectedFiles = file.value;
    });
}

它起作用了。你的小提琴只是没有正确初始化AngularJS。这里有一个工作示例:它正在工作。你的小提琴只是没有正确初始化AngularJS。下面是一个工作示例:看起来不受支持:看起来不受支持: