Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.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 正在更改背景图像,但该图像在设备上不工作_Javascript_Css_Angularjs_Ionic Framework_Firebase - Fatal编程技术网

Javascript 正在更改背景图像,但该图像在设备上不工作

Javascript 正在更改背景图像,但该图像在设备上不工作,javascript,css,angularjs,ionic-framework,firebase,Javascript,Css,Angularjs,Ionic Framework,Firebase,我有一个背景不断变化的div,所有东西都可以在web上工作(离子服务),没有错误,但是图像没有出现在任何设备上。变量号是来自firebase的一些数据,没有问题。我不确定问题出在哪里,如果有任何帮助,我将不胜感激!多谢各位 html= <div class="change" id="change" style="background: url(img/original.png) center; background-size: cover;"></div> html=

我有一个背景不断变化的div,所有东西都可以在web上工作(离子服务),没有错误,但是图像没有出现在任何设备上。变量号是来自firebase的一些数据,没有问题。我不确定问题出在哪里,如果有任何帮助,我将不胜感激!多谢各位

html= <div class="change" id="change" style="background: url(img/original.png) center; background-size: cover;"></div>
html=
js

firebaseRef.on('value',函数(dataSnapshot){
var number=dataSnapshot.val().length;
$scope.length=数量;
$scope.$apply();
firebaseRef.once('值',
函数(dataSnapshot){
$timeout(函数(){

如果(数字当您将ionic应用程序打包为本机时,资产URL将从
http
更改为
file
。您的代码似乎没有使用绝对路径。可能是访问本地文件时出现了一些安全问题?当您从外部源接收异步数据时,您没有通知Angular。请参阅@Kato,感谢您的回复,仍然添加超时后没有运气。更新了代码什么是
number
以及
dataSnapshot
在哪里使用?@Kato,我更新了代码片段以包含该内容。number是分配给firebase中某些数据的变量
    firebaseRef.on('value', function(dataSnapshot){
    var number = dataSnapshot.val().length;
        $scope.length = number;
        $scope.$apply();

   firebaseRef.once('value',
            function (dataSnapshot) { 
   $timeout(function() {

            if (number <= 3){document.getElementById("change").setAttribute("style", "background: url(../img/image1.png) center; background-size: cover;");}
            else if (number <= 6){document.getElementById("change").setAttribute("style", "background: url(../img/image2.png) center; background-size: cover;");}
                }, function (err) {
                    console.error("problem getting data");
                });
            });