上使用的图像路径-6ren"> 上使用的图像路径-我有一个 Ionic 应用程序,我将在其中截取该应用程序的屏幕截图。 我的问题是我需要获取要在图像标记 src 中使用的图像路径。但我不知道为什么没有发生。 这是我的代码: $scope.image -6ren">
gpt4 book ai didi

javascript - Ionic/Cordova - 获取要在 上使用的图像路径

转载 作者:行者123 更新时间:2023-12-03 05:44:21 25 4
gpt4 key购买 nike

我有一个 Ionic 应用程序,我将在其中截取该应用程序的屏幕截图。

我的问题是我需要获取要在图像标记 src 中使用的图像路径。但我不知道为什么没有发生。

这是我的代码:

$scope.image = {
src: ''
};

$scope.takeScreenshot = function() {

var screenshotLink,
screenshot = new Image(),
filename = '';

navigator.screenshot.save(function(error,res) {
if(error){
//console.error(error);
} else {
screenshotLink = res.filePath;
}
},'jpg',100,filename);

$scope.image.src = screenshotLink;

};//end_takeScreenshot


<img ng-src="{{ image.src }}" alt="foobar"/>

你们能帮我解决这个问题吗?

最佳答案

您需要将 $scope.image.src = ScreenshotLink 移动到 navigator.screenshot.save 的回调函数中。就像这样:

navigator.screenshot.save(function(error,res) {
if(error){
//console.error(error);
} else {
screenshotLink = res.filePath;
$scope.$apply( function() {
$scope.image.src = screenshotLink;
});
}
},'jpg',100,filename);

关于javascript - Ionic/Cordova - 获取要在 <img src =""> 上使用的图像路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40390135/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com