简体   繁体   English

AngularJS-为什么不调用该函数?

[英]Angularjs - why is not calling that function?

i wanna call a function when the app starts to show a modal, so i did ... 当应用开始显示模态时,我想调用一个函数,所以我确实...

I call the function with the onDeviceReady 我用onDeviceReady调用该函数

document.addEventListener("deviceready", onDeviceReady, false);

    function onDeviceReady() {
      openModal();  
    }

but the function is not calling, in console shows: Uncaught ReferenceError: openModal is not defined 但是该函数未调用,在控制台中显示:Uncaught ReferenceError:未定义openModal

The function on controller: 控制器上的功能:

$scope.openModal = function() {
      alert("funcionou!");
    $scope.modal.show();
  };

please help! 请帮忙!

Your code does not know your scope. 您的代码不知道您的范围。

You can run it when the controller is loaded. 您可以在加载控制器后运行它。

Like this: 像这样:

angular.module("controllers",[])
.controller("testController",
    function ($scope) {

        $scope.$on('$viewContentLoaded',
            function () {
                $scope.modal.show()
            });
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM