AngularJS“ng-view”不会隐藏在路线

时间:2015-11-24 19:42:42

标签: javascript jquery angularjs ng-view

我在Cordova应用程序中遇到问题。我使用AngularJS,Kendo-UI和jQuery。

问题是在具有角度路由的路由之后,AngularJS正在创建新的ng视图而不删除旧的视图。

因此,旧内容和新内容将相互显示。每次在路线上都会创建一个新的ng-view。

我该怎么做才能阻止这种行为?

HTML码:

<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>Demo</title>

    <link href="css/normalize.css" rel="stylesheet">
    <link href="css/bootstrap.css" rel="stylesheet">
    <link href="css/kendo.common-material.css" rel="stylesheet">
    <link href="css/kendo.default.css" rel="stylesheet">
    <link href="css/kendo.material.css" rel="stylesheet">
    <link href="css/kendo.mobile.common.css" rel="stylesheet">
    <link href="css/kendo.mobile.android.light.css" rel="stylesheet">
    <link href="css/app.css" rel="stylesheet">

    <script src="lib/winstore-jscompat.js"></script>
    <script src="lib/jquery.min.js"></script>
    <script src="lib/angular.js"></script>
    <script src="lib/angular-route.js"></script>
    <script src="lib/kendo.mobile.min.js"></script>
    <script src="lib/kendo.all.min.js"></script>
    <script src="lib/promise.js"></script>
    <script src="cordova.js"></script>

    <script src="app/app.js"></script>
    <script src="app/router.js"></script>

    <!-- Controller JS-Files -->

</head>

<body>
    <a id="winui-sidebar-visibility-toggle" href="#">
        <img src="img/hamburger-menu.png">
    </a>
    <nav id="winui-sidebar">
        <div id="winui-sidebar-main">
            <a title="Tagesinfos" class="winui-sidebar-button" id="winui-sidebar-button-tagesinfos" href="#/tagesinfos">
                <img src="img/kalender.png">Tagesinfos</a>
            <a title="Tag" class="winui-sidebar-button" id="winui-sidebar-button-tag" href="#/tag">
                <img src="img/abschliessen.png">Tag</a>
            <a title="Kundeinfo anzeigen" class="winui-sidebar-button winui-sidebar-button-subitem" id="winui-sidebar-button-kundenstammdaten" href="#/kundenstammdaten/KND_10936">
                <img src="img/allgemein.png">Kundeinfo anzeigen</a>
            <a title="Besuchsbericht" class="winui-sidebar-button winui-sidebar-button-subitem" id="winui-sidebar-button-besuchsbericht" href="#/besuchsbericht">
                <img src="img/bericht.png">Besuchsbericht</a>
            <a title="Überfällige Kunden" class="winui-sidebar-button" id="winui-sidebar-button-ueberfaelligekunden" href="#/ueberfaelligekunden">
                <img src="img/kunde.png">Überfällige Kunden</a>
            <a title="Einzelbelege &amp; Sonderzeiten" class="winui-sidebar-button" id="winui-sidebar-button-belegezeiten" href="#/belegezeiten">
                <img src="img/belegezeiten.png">Einzelbelege &amp; Sonderzeiten</a>
            <a title="Allgemeines Informationsmodul" class="winui-sidebar-button" id="winui-sidebar-button-infosmodul" href="#/infosmodul">
                <img src="img/allgemein.png">Allgemeines Informationsmodul</a>
        </div>
        <div id="winui-sidebar-bottom">
            <hr>
            <a title="Sync" class="winui-sidebar-button" id="winui-sidebar-button-sync" href="#/sync">
                <img src="img/sync.png">Sync</a>
            <a title="Einstellungen" class="winui-sidebar-button" id="winui-sidebar-button-settings" href="#/settings">
                <img src="img/settings.png">Einstellungen</a>
        </div>
    </nav>

    <header id="winui-header">
        <a id="winui-back" style="display: none;" href="#">
            <img src="img/back.png">
        </a>
        <h1 class="ng-binding">Tagesinfos</h1>
    </header>

    <div id="winui-content">
        <div class="content ng-scope" ng-view="">
        </div>
    </div>
</body>

路线:

angular.module('app').config(['$routeProvider', '$compileProvider', function($routeProvider, $compileProvider) {
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|file|ghttps?|ms-appx|x-wmapp0):/);
$compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|file|ms-appx|x-wmapp0):|data:image\//);

$routeProvider.when('/', {
    templateUrl: 'app/pages/Tagesinfos.html',
    controller: 'TagesinfosCtrl'
}).when('/settings', {
    templateUrl: 'app/pages/Settings.html',
    controller: 'SettingsCtrl'
}).when('/sync', {
    templateUrl: 'app/pages/Sync.html',
    controller: 'SyncCtrl'
}).when('/infosmodul', {
    templateUrl: 'app/pages/Infosmodul.html',
    controller: 'InfosmodulCtrl'
}).when('/artikelstammdaten/:id', {
    templateUrl: 'app/pages/Artikelstammdaten.html',
    controller: 'ArtikelstammdatenCtrl'
}).when('/kundenstammdaten/:id', {
    templateUrl: 'app/pages/Kundenstammdaten.html',
    controller: 'KundenstammdatenCtrl'
}).when('/tagesinfos', {
    templateUrl: 'app/pages/Tagesinfos.html',
    controller: 'TagesinfosCtrl'
}).when('/tag', {
    templateUrl: 'app/pages/Tag.html',
    controller: 'TagCtrl'
}).when('/kundeanmelden', {
    templateUrl: 'app/pages/Kundeanmelden.html',
    controller: 'KundeanmeldenCtrl'
}).when('/besuchsbericht', {
    templateUrl: 'app/pages/Besuchsbericht.html',
    controller: 'BesuchsberichtCtrl'
}).when('/taetigkeit/:besuchsbericht_id/:id', {
    templateUrl: 'app/pages/Taetigkeit.html',
    controller: 'TaetigkeitCtrl'
}).when('/sonderzeit/:id', {
    templateUrl: 'app/pages/Sonderzeit.html',
    controller: 'SonderzeitCtrl'
}).when('/einzelbeleg/:id', {
    templateUrl: 'app/pages/Einzelbeleg.html',
    controller: 'EinzelbelegCtrl'
}).when('/belegezeiten', {
    templateUrl: 'app/pages/Belegezeiten.html',
    controller: 'BelegezeitenCtrl'
}).when('/ueberfaelligekunden', {
    templateUrl: 'app/pages/UeberfaelligeKunden.html',
    controller: 'UeberfaelligeKundenCtrl'
}).otherwise({
    redirectTo: '/'
});
}]);

最诚挚的问候

约翰

0 个答案:

没有答案