未在angularJS和Ionic中加载模板

Templates not loading in angularJS and Ionic

本文关键字:加载 Ionic angularJS 未在      更新时间:2023-09-26

我设置了一个基本的ionic应用程序,其中包含一些视图和控制器。当我加载起始页时,我总是以$urlRouterProvider.otherwise('views/error.html');行结束。也没有加载任何模板。。即使是错误.html.

我不知道为什么。我在控制台中没有js错误或其他任何错误。有什么想法吗?

这是我的代码:

html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title></title>
    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/ionic.app.css" rel="stylesheet">
    -->
    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>
    <!-- cordova script (this will be a 404 during development) -->
    <script src="cordova.js"></script>
    <!-- your app's js -->
    <script src="js/app.js"></script>
    <script src="js/controllers/LoginController.js"></script>
    <script src="js/controllers/MainMenuController.js"></script>
    <script src="js/controllers/SettingsController.js"></script>
  </head>
  <body ng-app="iou">
    <ion-nav-view></ion-nav-view>
  </body>
</html>

javascript

var app = angular.module('iou', ['ionic'])
.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if(window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
});
app.config(function($stateProvider, $urlRouterProvider) {
    $stateProvider.state('index', {
        url: '/',
        templateUrl: 'views/login.html',
        controller: 'LoginController'
    });
    $stateProvider.state('mainmenu', {
        url: '/mainmenu',
        templateUrl: 'views/mainmenu.html',
        controller: 'MainMenuController'
    });
    $stateProvider.state('settings', {
        url: '/settings',
        templateUrl: 'views/settings.html',
        controller: 'SettingsController'
    });
    $urlRouterProvider.otherwise('views/error.html'); // I always end up here
});

errors.html在您的视图文件夹中,并且有一些标记要渲染$urlRouteProvider.否则('directory/file.html')将始终在应用程序启动时首先加载。

所以我的解决方案是更改:

$urlRouterProvider.otherwise('views/error.html');

至:

$urlRouterProvider.otherwise('/');