Не удается вызвать функции в кордове - визуальная студия

Я создаю первое приложение Cordova с помощью инструментов Visual Studio Cordova.
Я использую Windows 7 и VS Community (если это важно) и эмулятор ripple.
Проблема в том, что у меня есть такой код: <button onclick="showAlert(); return false;">Click Me</button> и мой функция определена in index.ts.
Но я получаю сообщение об ошибке Exception: showAlert is not defined при нажатии на кнопку.
Что мне здесь не хватает?
Это полный код:
index.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Cordova01</title>

    <!-- Cordova01 references -->
    <link href="css/index.css" rel="stylesheet" />
</head>
<body>
    <p>Hello, your application is ready!</p>
    <p><strong>Hello, from Cordova :)</strong></p>
    <button onclick="showAlert(); return false;">Click Me</button>
    <!-- Cordova reference, this is added to your app when it's built. -->
    <script src="cordova.js"></script>    
    <script src="scripts/platformOverrides.js"></script>
    <script src="scripts/index.js"></script>
</body>
</html>

index.ts

module Cordova01 {
    "use strict";

    export module Application {
        export function initialize() {
            document.addEventListener('deviceready', onDeviceReady, false);
        }

        function onDeviceReady() {
            // Handle the Cordova pause and resume events
            document.addEventListener('pause', onPause, false);
            document.addEventListener('resume', onResume, false);

            // TODO: Cordova has been loaded. Perform any initialization that requires Cordova here.

        }

        function showAlert() {
            navigator.notification.alert(
                "This is simple message!",  // message
                null,       // callback
                "Alert View Title", // title
                'OK'        // buttonName
                );    
        }

        function onPause() {
            // TODO: This application has been suspended. Save application state here.
        }

        function onResume() {
            // TODO: This application has been reactivated. Restore application state here.
        }

    }

    window.onload = function () {
        Application.initialize();
    }


}

person 1110    schedule 09.12.2014    source источник


Ответы (1)


Вы почти у цели, вам следует изменить функцию showAlert на export function showAlert() И в html также изменить ее <button onclick="Cordova01.Application.showAlert(); return false;">Click Me</button>

В вашем случае он не смог найти функцию showAlert, потому что она находится в модуле. Другой способ — вынести функцию showAlert из модуля для тестирования, это тоже должно сработать!

См. пример скрипки: fiddle

person Dick van den Brink    schedule 09.12.2014