javascript - 从index.html javascript调用angularJS Controller 函数

标签 javascript angularjs cordova phonegap-plugins

我创建了一个 Ionic、AngularJS、phonegap/cordova 应用程序。

在我的 index.html 中,我有这段纯 JavaScript 代码片段:

  <script src="js/analytics/launchMyApp.js"></script>
  <script type="text/javascript">

    function handleOpenURL(url) {
        // This function is triggered by the LaunchMyApp Plugin
        setTimeout(function() {
        alert("Hey the URL: " + url);
        console.log(">>>>>>>>> Take me to the launchMyApp controller: " + url);

        // Call controller function here

        }, 3000);
    }

</script>

handleOpenURL 函数由 launchMyApp 插件触发:

  nl.x-services.plugins.launchmyapp

这是我的 Controller :

  communicatorApp.controller('LaunchMyAppCtrl', function($scope, $state) {

     console.log(">>>>>>>> COOL!!!!");

     $scope.launchMyAppHere = function(urlIn) {
         console.log(">>>>>>>> GO MAN GO: " + urlIn);
     };

  });

我的问题是我不知道如何从index.html javascript 调用launchMyAppHere 函数?

最佳答案

试试这个:

angular.element($("#elementID")).scope().launchMyAppHere();

其中 #elementID 是附加 Controller 的元素的 DOM ID。

关于javascript - 从index.html javascript调用angularJS Controller 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25059029/

相关文章:

javascript - 包含用于在 passport-local 中注册的电子邮件的输入字段是否必须具有属性 'name = username' ?

javascript - 使用带有条件javascript的 map 从数组中提取id

javascript - 无法使用 ng-repeat 检索动态创建的 JSON 对象的属性

javascript - 如何使用 AngularJs 刷新 Ng-repeat

javascript - 为什么AngularJS ngInlude的优先级执行在400?

ajax - 绑定(bind)到函数,从 $http.get 获取结果

facebook - Inappbrowser回调

android - 当应用程序不在前台时,Ionic/Cordova 触发应用程序操作

windows - Cordova 构建 Windows 错误 - 缺少 Microsoft.WinJS.2.0

javascript - Html5 辅助文件?