Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.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 禁用iframe的src侦听器_Javascript_Angularjs_Asynchronous_Iframe_Angularjs Watch - Fatal编程技术网

Javascript 禁用iframe的src侦听器

Javascript 禁用iframe的src侦听器,javascript,angularjs,asynchronous,iframe,angularjs-watch,Javascript,Angularjs,Asynchronous,Iframe,Angularjs Watch,我的模板中有一个iframe,src指的是一个物理html文件 <iframe id="myiframe" src="{{src}}"> </iframe> 我的测试显示,有时它可以正常工作,但有时会给出以下日志: rewriteAllFiles /emptyDir, done GET http://localhost:3000/tmp/P0L7JSEOWux3YE1FAAA6/index.html 404 (Not Found) rewriteAllFiles /wr

我的模板中有一个iframe,
src
指的是一个物理html文件

<iframe id="myiframe" src="{{src}}">
</iframe>
我的测试显示,有时它可以正常工作,但有时会给出以下日志:

rewriteAllFiles /emptyDir, done
GET http://localhost:3000/tmp/P0L7JSEOWux3YE1FAAA6/index.html 404 (Not Found)
rewriteAllFiles /writeFiles, done
refreshIframe, done
因此,似乎在删除旧文件之后和写入新文件之前,html模板会尝试加载
src
,因此该文件暂时不可用。我没有为
src
设置监视程序,有人知道
src
的侦听器在哪里,以及如何禁用它吗

编辑1:以下是服务器端的
writefile
代码:

router.post('/writeFiles', function (req, res, next) {
    var dir = req.body.dir, files = req.body.files;
    var fs = require('fs');
    var queue = files.map(function (file) {
        return new Promise(function (resolve, reject) {
            fs.writeFile(dir + file.name, file.body, function (err) {
                if (err) return reject(err);
                console.log(dir + file.name + " is written");
                resolve(file);
            })
        })
    });

    Promise.all(queue)
        .then(function(files) {
            console.log("All files have been successfully written");
            res.json(dir);
        })
        .catch(function (err) {
            return console.log(err)
        });
});

你可以试试{{::src}。只需渲染一次。

您可以尝试{{::src}。只需渲染一次。

我意识到它与控制器中的另一行代码有关

$scope.src = getSrc() // getSrc(); returns the right html link initiated by a resolving 

$scope.$watch(... {
    return rewriteAllFiles($location.path(), $scope.files);
})
当我们加载模板时,上面的代码可能会在删除旧文件之后和写入新文件之前执行
$scope.src=getSrc()
,这会引发
未找到
错误

所以我们只需要通过
然后
确定执行顺序;以下代码起作用:

$scope.$watch(... {
    return rewriteAllFiles($location.path(), $scope.files)
        .then(function () {
            $scope.src = getSrcP();
        });
});

我意识到它与控制器中的另一行代码有关

$scope.src = getSrc() // getSrc(); returns the right html link initiated by a resolving 

$scope.$watch(... {
    return rewriteAllFiles($location.path(), $scope.files);
})
当我们加载模板时,上面的代码可能会在删除旧文件之后和写入新文件之前执行
$scope.src=getSrc()
,这会引发
未找到
错误

所以我们只需要通过
然后
确定执行顺序;以下代码起作用:

$scope.$watch(... {
    return rewriteAllFiles($location.path(), $scope.files)
        .then(function () {
            $scope.src = getSrcP();
        });
});

我尝试了
,它仍然给出一个错误。我尝试了
,它仍然给出一个错误。应该使用
ng src
。听起来post请求是在写入文件之前完成的,所以问题是服务器端我尝试了
,但它仍然给出未找到的错误。。。您能否详细说明一下
post请求正在完成…
?我建议您的服务器代码逻辑在文件写入之前发送响应。我刚刚在服务器端添加了
writefile
的代码…应该使用
ng src
。听起来post请求是在写入文件之前完成的,所以问题是服务器端我尝试了
,但它仍然给出未找到的错误。。。您能否详细说明一下
post请求正在完成…
?我建议您的服务器代码逻辑正在写入文件之前发送响应。我刚刚在服务器端添加了
writefile
的代码。。。