CordovaApp-AngularJs-app.initialize()->未定义不是函数

用户名

我有一个由cordova + onsen + angularJs制成的android混合体。

这是index.html文件:

<html>
<head>
    <meta charset="utf-8">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="mobile-web-app-capable" content="yes">
    <title>AppModel</title>  

    <!-- <link rel="stylesheet" href="css/plugins.css"/> -->
    <link rel="stylesheet/less" href="css/plugins.less"/>

    <link rel="stylesheet" href="lib/onsen/css/onsenui.css">  
    <link rel="stylesheet" href="lib/onsen/css/onsen-css-components.css">  

    <link rel="stylesheet/less" href="css/app.less"/>
    <link rel="stylesheet/less" href="css/base-layout.less"/>

</head>

<body>    

<ons-sliding-menu
    menu-page="modules/core/menu.html" main-page="modules/account_profile/login.html" side="left"
    var="menu" type="reveal" max-slide-distance="260px" swipable="true" swipe-target-width="50">
</ons-sliding-menu>


<script src="css/less.min.js" type="text/javascript"></script>


<script src="lib/onsen/js/angular/angular.js"></script>   
<script src="lib/onsen/js/angular/angular-touch.js"></script>    
<script src="lib/onsen/js/onsenui.min.js"></script>  

  <script src="http://maps.google.com/maps/api/js?sensor=false"></script>         
  <script src="js/lodash_3.2.0.min.js"></script>  
  <script src="js/angular-google-maps_2.0.12.min.js"></script>
    <script src="js/jquery.min.js"></script>   
<script src="js/plugins.js"></script>   

<script src="js/appStart.js"></script>      
<script src="js/data/data.js"></script>    
<script src="js/angularApp/controllers.js"></script>      
<script src="js/angularApp/directives.js"></script>      
<script src="js/angularApp/filters.js"></script>    
<script type="text/javascript" src="cordova.js"></script>

  <script>
    app.initialize();
   </script>

  </body>
 </html>

这是appStart.js文件:

var app = {
// Application Constructor
initialize: function() {
    this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
    document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicity call 'app.receivedEvent(...);'

exitFunction : function(){
     if (navigator.notification.confirm("Vuoi chiudere l'app?", 
            function(index) {
                if (index == 1) { // OK button
                    navigator.app.exitApp(); // Close the app
                }
            },
            "AppModel",
            ["Ok","Annulla"]
        ));
},

onDeviceReady: function() {
    app.receivedEvent('deviceready');

    ons.setDefaultDeviceBackButtonListener(function() {
        if (navigator.notification.confirm("Vuoi chiudere l'app?", 
            function(index) {
                if (index == 1) { // OK button
                    navigator.app.exitApp(); // Close the app
                }
            },
            "AppModel",
            ["Ok","Annulla"]
        ));
    });

    /*
    // Open any external link with InAppBrowser Plugin
    $(document).on('click', 'a[href^=http], a[href^=https]', function(e){

        e.preventDefault();
        var $this = $(this); 
        var target = $this.data('inAppBrowser') || '_blank';

        window.open($this.attr('href'), target);

    });
    */

    $(document).on('click', 'a', function(e){

        e.preventDefault();
        var $this = $(this); 
        //var target = $this.data('inAppBrowser') || '_blank';

        window.open($this.attr('href'), "_system");

    });


},
// Update DOM on a Received Event
receivedEvent: function(id) {
    //var parentElement = document.getElementById(id);
    //var listeningElement = parentElement.querySelector('.listening');
    //var receivedElement = parentElement.querySelector('.received');

    //listeningElement.setAttribute('style', 'display:none;');
    //receivedElement.setAttribute('style', 'display:block;');

    console.log('Received Event: ' + id);
}

};


(function() {

var app = angular.module('AppModel', ['onsen', 'angular-carousel', 'uiGmapgoogle-maps'])    
.config( [
    '$compileProvider',
    function( $compileProvider )
    {   
        $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|file|ftp|mailto|tel|geo):/);            
    }
]);


document.addEventListener('deviceready', function() {
    angular.bootstrap(document, ['AppModel']);       
}, false);    


})();

但是Chrome检查控制台说,undefined不是函数,引用index.html中的脚本

   <script>app.initialize();</script>

有什么问题?谢谢

用户名

自己找到解决方案:

我创建了一个新文件,名为index.js,这是内容

var app = {
// Application Constructor
initialize: function() {
    this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
    document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicity call 'app.receivedEvent(...);'

exitFunction : function(){
     if (navigator.notification.confirm("Vuoi chiudere l'app?", 
            function(index) {
                if (index == 1) { // OK button
                    navigator.app.exitApp(); // Close the app
                }
            },
            "AppModel",
            ["Ok","Annulla"]
        ));
},

onDeviceReady: function() {
    app.receivedEvent('deviceready');

    ons.setDefaultDeviceBackButtonListener(function() {
        if (navigator.notification.confirm("Vuoi chiudere l'app?", 
            function(index) {
                if (index == 1) { // OK button
                    navigator.app.exitApp(); // Close the app
                }
            },
            "AppModel",
            ["Ok","Annulla"]
        ));
    });

    /*
    // Open any external link with InAppBrowser Plugin
    $(document).on('click', 'a[href^=http], a[href^=https]', function(e){

        e.preventDefault();
        var $this = $(this); 
        var target = $this.data('inAppBrowser') || '_blank';

        window.open($this.attr('href'), target);

    });
    */

    $(document).on('click', 'a', function(e){

        e.preventDefault();
        var $this = $(this); 
        //var target = $this.data('inAppBrowser') || '_blank';

        window.open($this.attr('href'), "_system");

    });


},
// Update DOM on a Received Event
receivedEvent: function(id) {
    //var parentElement = document.getElementById(id);
    //var listeningElement = parentElement.querySelector('.listening');
    //var receivedElement = parentElement.querySelector('.received');

    //listeningElement.setAttribute('style', 'display:none;');
    //receivedElement.setAttribute('style', 'display:block;');

    console.log('Received Event: ' + id);
}

 };


  app.initialize(); //moved here this instruction

然后在index.html正文中,作为最后导入的脚本:

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

一切正常。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

TypeError:未定义不是函数-AngularJS

来自分类Dev

TypeError:未定义不是函数(AngularJS)

来自分类Dev

AngularJS-参数“ MenuCtrl”不是函数,未定义

来自分类Dev

angularjs + requirejs =参数'controller'不是函数,未定义

来自分类Dev

angularjs推送对象未定义不是函数

来自分类Dev

angularjs TypeError:未定义不是函数工厂

来自分类Dev

angularJS 1.4.0参数'MainController'不是函数,未定义

来自分类Dev

未定义不是构造函数,angularjs指令测试

来自分类Dev

AngularJS错误:参数“ FirstCtrl”不是函数,未定义

来自分类Dev

AngularJS控制器不是函数,未定义

来自分类Dev

angularjs + ionic + php mysql(未定义不是函数)

来自分类Dev

AngularJS:未捕获ReferenceError:未定义angular app.js:1(匿名函数):

来自分类Dev

未定义的AngularJS常量不是对象

来自分类Dev

指令的AngularJS链接函数未定义

来自分类Dev

函数返回未定义的AngularJS

来自分类Dev

PubNub AngularJS未定义函数ngSubscribe

来自分类Dev

函数返回AngularJS中未定义的

来自分类Dev

超时angularjs中的未定义函数

来自分类Dev

AngularJs函数形式未定义

来自分类Dev

在angularjs中未定义函数参数

来自分类Dev

AngularJS分离控制器,参数不是函数,它是未定义的

来自分类Dev

如何找到原因AngularJS“参数'MyCtrl'不是函数,未定义”

来自分类Dev

使用angularjs和d3 TypeError的制图:未定义不是函数

来自分类Dev

AngularJS-错误控制器不是函数,未定义

来自分类Dev

AngularJS / Jade错误:参数'MyController'不是一个函数,未定义(MEAN)

来自分类Dev

在angularJS中使用工厂方法时,未定义不是函数错误

来自分类Dev

AngularJS $ http.get返回未定义且$ http()不是函数

来自分类Dev

参数'MainController'不是一个函数,在AngularJS中未定义

来自分类Dev

AngularJS控制器错误-TypeError:未定义不是函数

Related 相关文章

  1. 1

    TypeError:未定义不是函数-AngularJS

  2. 2

    TypeError:未定义不是函数(AngularJS)

  3. 3

    AngularJS-参数“ MenuCtrl”不是函数,未定义

  4. 4

    angularjs + requirejs =参数'controller'不是函数,未定义

  5. 5

    angularjs推送对象未定义不是函数

  6. 6

    angularjs TypeError:未定义不是函数工厂

  7. 7

    angularJS 1.4.0参数'MainController'不是函数,未定义

  8. 8

    未定义不是构造函数,angularjs指令测试

  9. 9

    AngularJS错误:参数“ FirstCtrl”不是函数,未定义

  10. 10

    AngularJS控制器不是函数,未定义

  11. 11

    angularjs + ionic + php mysql(未定义不是函数)

  12. 12

    AngularJS:未捕获ReferenceError:未定义angular app.js:1(匿名函数):

  13. 13

    未定义的AngularJS常量不是对象

  14. 14

    指令的AngularJS链接函数未定义

  15. 15

    函数返回未定义的AngularJS

  16. 16

    PubNub AngularJS未定义函数ngSubscribe

  17. 17

    函数返回AngularJS中未定义的

  18. 18

    超时angularjs中的未定义函数

  19. 19

    AngularJs函数形式未定义

  20. 20

    在angularjs中未定义函数参数

  21. 21

    AngularJS分离控制器,参数不是函数,它是未定义的

  22. 22

    如何找到原因AngularJS“参数'MyCtrl'不是函数,未定义”

  23. 23

    使用angularjs和d3 TypeError的制图:未定义不是函数

  24. 24

    AngularJS-错误控制器不是函数,未定义

  25. 25

    AngularJS / Jade错误:参数'MyController'不是一个函数,未定义(MEAN)

  26. 26

    在angularJS中使用工厂方法时,未定义不是函数错误

  27. 27

    AngularJS $ http.get返回未定义且$ http()不是函数

  28. 28

    参数'MainController'不是一个函数,在AngularJS中未定义

  29. 29

    AngularJS控制器错误-TypeError:未定义不是函数

热门标签

归档