新しい変数(targetPath)を作成するときにメソッドを呼び出そうとしていますが、ローカルアンドロイドの正しいディレクトリにビデオをダウンロードするために必要なすべてのデータを取得するストレージ。しかし、私のメソッドが呼び出されるときに問題を起こすのは、定義されていないか、$ scope.callMethodを使用した場合、スコープは定義されません。スコープが定義されておらず、Angularjsモジュールの関数を呼び出す
var targetPath = scope.getFilePath();
//Gets the URL of where to download from
$scope.getURL = function() {
//Whatever URL we want
var url = "http://static.videogular.com/assets/videos/videogular.mp4";
return url;
}
//Gets the filename of any URL we download from
$scope.getFileName = function() {
//Splits the URL
var filename = scope.getURL().split("/").pop();
return filename;
}
//This function is used to get the directory path so we can use it for other functions
$scope.getFilePath = function() {
//Use this code for internal file download
var targetPath = cordova.file.externalDataDirectory + scope.getFileName();
return targetPath;
}
FULL CODE HERE
angular.module('starter.controllers', [])
.controller('AppCtrl', function ($scope, $ionicModal, $timeout, $cordovaFileTransfer, $sce) {
//Gets the URL of where to download from
$scope.getURL = function() {
//Whatever URL we want
var url = "http://static.videogular.com/assets/videos/videogular.mp4";
return url;
}
//Gets the filename of any URL we download from
$scope.getFileName = function() {
//Splits the URL
var filename = scope.getURL().split("/").pop();
return filename;
}
//This function is used to get the directory path so we can use it for other functions
$scope.getFilePath = function() {
//Use this code for internal file download
var targetPath = cordova.file.externalDataDirectory + scope.getFileName();
return targetPath;
}
//download file function
$scope.downloadFile = function() {
//Keeps track of progress bar
var statusDom = document.querySelector('#status');
var myProgress = document.querySelector("#myProgress");
//URL where the video is downloaded from
//var url = "http://static.videogular.com/assets/videos/videogular.mp4";
//Splits the URL
// var filename = url.split("/").pop();
//alert(filename);
//Interal storage
//Use this code for internal file download
var targetPath = scope.getFilePath();
var trustHosts = true
var options = {};
//Makes sure that the URL is trusted to get around permission issues at download
console.log($sce.trustAsResourceUrl(scope.getURL()));
$cordovaFileTransfer.download(scope.getURL(), scope.getFilePath(), options, trustHosts)
.then(function (result) {
// Success!
alert(JSON.stringify(result));
}, function (error) {
// Error
alert(JSON.stringify(error));
}, function (progress) {
//Shows how much the file has loaded
if (progress.lengthComputable) {
var perc = Math.floor(progress.loaded/progress.total * 100);
statusDom.innerHTML = perc + "% loaded...";
myProgress.value = perc;
} else {
if (statusDom.innerHTML == "") {
statusDom.innerHTML = "Loading";
} else {
statusDom.innerHTML += ".";
}
}
})
}
})
誰も私にもいただければ幸いですangularjsでこれらの関数を呼び出すための正しい方法を表示してください可能性があります。
$ scope.getURL()と$ scope.getFilePath()を使用すると、コンソールには何が表示されるのですか? – strelok2010
私は間違いを認識しています。以前のテストで$文字を無視していたと思っていましたが、$ scopeでうまく動いています – user221