Kendo - Cordova - Navigation - Uncaught TypeError:无法调用未定义的方法'triggerBeforeShow'

时间:2016-04-04 15:00:42

标签: javascript android angularjs cordova kendo-ui

我收到错误Uncaught TypeError:无法在设备或非涟漪模拟器上运行的kendo移动corova项目中调用未定义的方法'triggerBeforeShow'。

错误似乎与导航有关。

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <!--
            Customize the content security policy in the meta tag below as needed. Add 'unsafe-inline' to default-src to enable inline JavaScript.
            For details, see http://go.microsoft.com/fwlink/?LinkID=617521
            -->
        <meta http-equiv="Content-Security-Policy" content="default-src  'self' http://cdn.kendostatic.com  http://ajax.googleapis.com http://code.jquery.com  https://caredarewebapi.azurewebsites.net  https://localhost:44309/   https://localhost:44300/  https://caredarestorage.blob.core.windows.net/ 'unsafe-eval' 'unsafe-inline' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
        <title>CorovaStartupNavigationTest</title>
        <!-- CorovaStartupNavigationTest references -->
        <link href="css/kendo.mobile.all.min.css" rel="stylesheet" />
        <script src="scripts/index.js"></script>
    </head>
    <body kendo-mobile-application skin="'flat'" ng-app="sushiMobileApp">
        <kendo-mobile-view id="index" ng-controller="indexController">
            <kendo-mobile-header>
                <kendo-mobile-nav-bar>
                    Home View
                    <kendo-mobile-button k-align="'right'" data-icon="'contacts'" id="btnProfile" k-on-click="mnuProfile.open($('#btnProfile'))"></kendo-mobile-button>
                </kendo-mobile-nav-bar>
            </kendo-mobile-header>
            <ul kendo-mobile-action-sheet="mnuProfile" k-type="'phone'" k-on-command="onCommand(kendoEvent)">
                <li><a href="#" data-command="login">Login</a></li>
                <li ng-hide="(authentication.token.length == 0)"><a href="#" data-command="logout">Logout</a></li>
                <li><a href="#" data-command="showProfile">My Profile</a></li>
            </ul>
        </kendo-mobile-view>
        <script src="cordova.js"></script>
        <script src="scripts/platformOverrides.js"></script>
        <script src="scripts/jquery.min.js"></script>
        <script src="scripts/angular.js"></script>
        <script src="scripts/kendo.all.min.js"></script>
        <script src="app/modules/cdlogin.js"></script>
        <script>
            angular.module('sushiMobileApp', ['kendo.directives', 'cdlogin'])
             .controller('indexController', ['$scope', function ($scope) {
                 $scope.showHome = function (kendoEvent) {
                     kendo.mobile.application.navigate("/app/views/viewtabhome.html");
                 }

                 $scope.onCommand = function (kendoEvent) {
                     $scope.command = kendoEvent.currentTarget.data("command");
                     switch ($scope.command) {
                         case "login":
                             kendo.mobile.application.navigate('/app/views/viewlogin.html');
                             break;
                     }
                 }
             }]);
            ;
        </script>
    </body>
</html>
<!-- Login View -->
<kendo-mobile-view id="viewLogin" data-title="Login" ng-controller="loginCtrl" k-on-before-show="beforeShow(kendoEvent)">
    <kendo-mobile-header>
        <kendo-mobile-nav-bar>
            <kendo-mobile-back-button data-align="left"  >Back</kendo-mobile-back-button>
            Login
        </kendo-mobile-nav-bar>
    </kendo-mobile-header>
    <div class="container">
        <div class="col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2" style="margin-top:50px">
        <form id="frmLogin" kendo-validator="validatorLogin" ng-submit="validate($event)">
            <div>Logged in as {{authSrv}}</div>
            <div class="form-group">
                <label for="txtLoginUserName">Email:</label>
                <input class="form-control" type="text" ng-model="txtLoginUserName" id="txtLoginUserName" placeholder="Enter" name="User Name" required="required" />
                <span class="k-invalid-msg" data-for="txtLoginUserName"> </span>
            </div>
            <div class="form-group">
                <label for="txtLoginPassword">Password:</label>
                <input class="form-control" type="password" ng-model="txtLoginPassword" id="txtLoginPassword" placeholder="Enter" name="Password" required="required" />
            </div>
            <nobr>
                <div class="checkbox">
                    <label>
                    Remember Me:
                    <input style="margin-left:10px" type="checkbox" ng-model="LoginRememberMe" id="chkLoginRememberMe" ng-click="rememberMe()" />
                    </label>
                </div>
            </nobr>
            <span class="alert alert-info" k-append-to="'#lblLoginErrors'" kendo-notification="staticNotification"></span>
            <div style="text-align:center">
                <span id="lblLoginErrors" style="width:100%"></span><br />
                <input type="submit" style="position: absolute; left: -9999px; width: 1px; height: 1px;" />
                <kendo-mobile-button ng-click="login()" class="k-primary" ng-disabled="notLoggingIn != true">
                    Log in
                </kendo-mobile-button>
                <p>
                    <kendo-mobile-button ng-click="register()">Register</kendo-mobile-button>
                    if you don't have a local account.
                </p>
            </div>
            <div class="list-group" id="divExternalLogins">
                <a href="#" class="list-group-item " style="height:60px" ng-repeat="dsDataItem in dsExternalLoginProviders.data()" ng-click="login(dsDataItem)">
                <i class="{{dsDataItem.icon}} fa-5"></i>&nbsp; Sign in with {{dsDataItem.name}}
                </a>
            </div>
        </form>
        </div>
    </div>
    <div id="winLogin" kendo-window="winLogin" k-title="'Login'"
        k-width="600" k-height="400" k-visible="false"
        k-on-open="winLoginvisible = true" k-on-close="onClose();winLoginvisible = false"></div>
</kendo-mobile-view>

function LoginCtrl($scope) {
    $scope.beforeShow = function () {}
}
LoginCtrl.$inject = ['$scope'];    
angular.module('cdlogin', ['kendo.directives']).controller('loginCtrl', LoginCtrl);

1 个答案:

答案 0 :(得分:0)

在android上的cordova中,前导/导航会破坏应用程序并抛出此错误。解决方案是将导航方法更改为:

&#13;
&#13;
kendo.mobile.application.navigate('app/views/viewlogin.html');
&#13;
&#13;
&#13;