【问题标题】:I want to create a application in ionic with multiple page but i am not able to link other pages to a button我想在 ionic 中创建一个具有多个页面的应用程序,但我无法将其他页面链接到按钮
【发布时间】:2017-07-25 10:34:36
【问题描述】:

我正在尝试制作这样的东西

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

如果您知道其他替代方法或教程或链接,请发布。

注意我正在将我的 ionic 项目代码完全复制到 plunker 中,以便您更好地理解它,但它可能无法在 plunker 中工作。

如果可以的话,请帮助我。

<[MY Plunker][2]>




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

【问题讨论】:

    标签: angularjs ionic-framework ionic2


    【解决方案1】:

    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) {
    
    });
    

    【讨论】:

    • raj home.html 和 second.html 的目录应该是什么
    • 您可以将这两个页面保存在 index.html 所在的同一目录中。
    • 感谢您的回答
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-14
    • 2023-03-18
    • 1970-01-01
    • 2022-01-16
    相关资源
    最近更新 更多