我想用多页创建离子应用程序,但我无法将其他页面链接到按钮

时间:2017-03-05 16:09:57

标签: angularjs ionic-framework ionic2

我正在尝试制作类似的东西< [Plunker] [1]>

但是当我在我的离子应用程序中尝试这个确切的代码时,屏幕上什么都没有。 我已经几次问过这个问题,但直到现在还没有人能帮助过我。

如果您了解其他替代方案或某些教程或链接,请发布。

注意我正在将我的离子项目代码复制到plunker中,以便您可以更好地理解它,但它可能不适用于plunker。

如果可以,请帮助我。

<[MY Plunker][2]>




  [1]: http://plnkr.co/edit/H5n7SM?p=preview
  [2]: https://plnkr.co/edit/fJTaer?p=preview

1 个答案:

答案 0 :(得分:0)

的index.html

<!DOCTYPE html>
<html data-ng-app="starter">
  <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">

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/ionic.app.css" rel="stylesheet">
    -->
    <script src="cordova.js"></script>
    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>
   <script src="js/angular-ui-router.min.js"></script>

    <!-- cordova script (this will be a 404 during development) -->

    <script src="https://cdnjs.cloudflare.com/ajax/libs/ng-cordova/0.1.27-alpha/ng-cordova.js"></script>

    <!-- your app's js -->
    <script src="js/app.js"></script>

    <script src="js/homeController.js"></script>
    <script src="js/secondController.js"></script>

  </head>
  <body>

    <ion-pane>
        <ion-content>
            <div id="wrapper" ui-view></div>
        </ion-content>
    </ion-pane>
  </body>
</html>

app.js

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

app.run(function($ionicPlatform) {
    $ionicPlatform.ready(function() {
      if(window.cordova && window.cordova.plugins.Keyboard) {
        // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
        // for form inputs)
        cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

        // Don't remove this line unless you know what you are doing. It stops the viewport
        // from snapping when text inputs are focused. Ionic handles this internally for
        // a much nicer keyboard experience.
        cordova.plugins.Keyboard.disableScroll(true);
      }
      ionic.Platform.fullScreen();
      if(window.StatusBar) {
        StatusBar.styleDefault();
      }
  });
})

 app.config(function($stateProvider, $urlRouterProvider){
  $stateProvider
    .state('index', {
      url: "",
          templateUrl: "home.html",
          controller: "homeController"            
    })

    .state('second', {
      url: "/second",
          templateUrl: "second.html",
          controller: "secondController"
    })
});

home.html的

<div style="width:100px;height: 50px;background-color: blue">home</div>
<button ui-sref="second">click</button>

second.html

<div style="width:100px;height: 50px;background-color: green">second</div>
<button ui-sref="index">click</button>

homeController.js

app.controller('homeController', function($scope,$ionicPlatform,$state) {

});

secondController.js

app.controller('secondController', function($scope,$ionicPlatform,$state) {

});