2016-12-15 13 views
2

我已经开始在离子应用程序的工作。点击按钮时,我正在从一个页面导航到另一个页面时遇到困难。这是我做了这么远按钮NG单击更改URL,但不会呈现新的看法?

index.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 rel="manifest" href="manifest.json"> 



    <link href="lib/ionic/css/ionic.css" rel="stylesheet"> 
    <link href="css/style.css" rel="stylesheet"> 

    <!-- ionic/angularjs js --> 
    <script src="lib/ionic/js/ionic.bundle.js"></script> 

    <script src="lib/ionic/js/angular/angular-resource.min.js"></script> 

    <script src="js/ng-cordova.min.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> 

    <base href="/"> 
    </head> 
    <body ng-app="starter"> 
    <div ng-controller="MainCtrl"> 
     <ion-content class="bg-img has-bottom"> 
     </ion-content> 
     <div class="fixed-outside">  
      <div class="row"> 
      <div class="col"> 
       <button ng-click="login_google()" class="button" id="google-btn">Connect with Google</button> 
      </div> 
      </div> 
      <div class="row"> 
      <div class="col"> 
       <button ng-click="login_fb()" class="button" id="fb-btn">Connect with Facebook</button> 
      </div> 
      </div> 
      <div class="row"> 
      <div class="col"> 
       <button class="button button-stable" ng-click="login()" id="login-btn">Login</button> 
      </div> 
      <div class="col"> 
       <button ng-click="register()" class="button button-stable" id="reg-btn">Register</button> 
      </div> 
      </div> 
     </div> 

    </body> 
</html> 

现在只专注于登录按钮。点击时应该导航到main.html。

app.js-

angular.module('starter', ['ionic','ui.router']) 


.config(function($stateProvider, $locationProvider, $urlRouterProvider){ 
    $urlRouterProvider.when('', '/'); 
    $stateProvider 
     .state('index', { 
      cache: false, 
      url: '/', 
        templateUrl: "index.html", 
        controller: "MainCtrl"  
     }) 
     .state('main',{ 
      cache: false, 
      url: '/main', 
      templateUrl: 'templates/main.html', 
      controller: 'MainController' 
     }); 
     $locationProvider.html5Mode(true); 
     $urlRouterProvider.otherwise('/'); 

}) 

.controller('MainCtrl', function($scope, $state) { 
    $scope.login = function(){ 
    //console.log("Login clicked!"); 
    $state.go('main'); 
    console.log('the state is '+$state.stateName); 
    // window.location = "/main.html"; 
    // $scope.apply(); 
    };  
}) 

.controller('MainController', function($scope, $state) {  
    $scope.message = 'This is student list screen'; 
}); 

控制台输出gives-

状态未定义

我找不到按钮的点击文件中的任何东西,以及简单的导航。

回答

1

你已经错过了调用index.html页面的脚本ui-router,这就是为什么你得到该错误消息。

但你并不需要注入ui-router如果你已经注入ionic模块

还需要下面的代码添加了绑定在html

<div ui-view></div>

更多详细资料请点击这里:How to Set Up HelloJS in Ionic Framework with Angular UI Router

+0

由于一吨!这工作 – user3813809