0


我在Ionic框架中的Angular導航遇到了一些麻煩。 我已經設置了兩個頁面(狀態),應用程序應該在打開時顯示第一個狀態。但是,$ urlRouterProvider.otherwise不工作(我認爲這是問題,至少)

我跟着oficial documentation和一些tutorials但沒有使它的工作。你能幫我麼?

var app = angular.module('famousguess', ['ionic', 'ui.router']) 
 

 
app.config(function($stateProvider, $urlRouterProvider) { 
 
\t 
 
\t $stateProvider 
 
\t .state('welcome', { 
 
\t \t url: '/', 
 
\t \t templateUrl: 'views/welcome.html', 
 
\t \t controller: 'WelcomeCtrl' 
 
\t }) 
 
\t .state('grid', { 
 
\t \t url: '/grid/:gridid', 
 
\t \t templateUrl: 'views/grid.html', 
 
\t \t controller: 'GridCtrl' 
 
\t }); 
 
\t 
 
\t $urlRouterProvider.otherwise('/'); 
 
}); 
 

 
app.controller('WelcomeCtrl', function ($scope, $state) { 
 
\t 
 
} 
 

 
app.controller('GridCtrl', function ($scope, $stateParams, $ionicHistory) { 
 
\t 
 
}
<!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>Famous Guess</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> 
 
    </head> 
 
    <body ng-app="famousguess" id="wrapper"> 
 
    
 
\t <ion-nav-bar class="bar-energized"> 
 
\t \t <ion-nav-back-button class="button-clear"> 
 
\t \t <i class="ion-arrow-left-c"></i> Back 
 
\t \t </ion-nav-back-button> 
 
\t </ion-nav-bar> 
 
\t 
 
\t <ion-nav-view></ion-nav-view> 
 

 

 
\t 
 
    </body> 
 
</html>

而且在這裏不用我的模板(的意見/ home.html做爲

<ion-view view-title="welcome"> 
     <ion-content scroll="false" class="box-energized"> 

     <h1 id="logo">Famous Guess?</h1> 

     <a nav-transition="android" href="#/grid/1"> 
      <button class="button button-block button-royal"> 
       Start! 
      </button> 
     </a> 

     <button class="button icon-left button-block button-positive ion-social-facebook"> 
      Connect to Facebook 
     </button> 

     </ion-content> 
</ion-view> 

謝謝!

回答

0

我想你已經在配置

$stateProvider 
     .state('welcome', { 
     url: '/', 
     templateUrl: 'views/home.html', 
     controller: 'WelcomeCtrl' 
     }) 
     .state('grid', { 
     url: '/grid/:gridid', 
     templateUrl: 'views/grid.html', 
     controller: 'GridCtrl' 
     }); 

    $urlRouterProvider.otherwise('/'); 
}); 

使用了錯誤的模板,我認爲上面會工作!您在tempalateurl中加載了錯誤的模板文件

+0

謝謝!我不確定這是否是問題,因爲我再次開始工作並開始工作。所以這個問題是一個錯字,可能是你指出的那個。 – IntegraStudio

相關問題