【问题标题】:Button click not open new page in ionic framework按钮单击未在离子框架中打开新页面
【发布时间】:2015-06-28 01:33:11
【问题描述】:

这是我的代码。当用户单击“登录”按钮时,我想打开一个新页面。我已经编写了配置函数并设置了状态名称。为什么我的"applicaion.html" 页面打不开。

在控制台中我可以看到用户名打印但$state.go('apps') 行不工作。

[http://codepen.io/skpatel/pen/XbVjKJ][1]
[1]: http://codepen.io/skpatel/pen/XbVjKJ

【问题讨论】:

    标签: angularjs ionic-framework ionic


    【解决方案1】:

    查看更新后的代码:http://codepen.io/anon/pen/PqEpbR?editors=101

    您在 index.html 中遗漏了以下内容:添加对管理视图更改的 ui-view(来自 ui-router)的引用。 您的代码在 index.html 中是静态的,没有引用新页面。

    UI 视图已添加到 index.html。这是ui-router 指令并且是强制性的。 Ionic 使用 ui-router

    <body>
      <div ui-view></div>
    </body>
    

    我已将登录页面的代码放入脚本模板中:

    <script type="text/ng-template" id="home.html">
    
      <ion-header-bar class="bar-calm">
            <h1 class="title">Application Permissions</h1>
        </ion-header-bar>
        <ion-content padding="true" has-header="true" padding="true" ng-controller="HomeCtrl">
            <p>Welcome to the privacy mirror home page!</p>
            <p>Enter your name and then you can just tap the login button to be logged in</p>
            <label class="item item-input" class="padding">
                <input type="text" placeholder="Username" ng-model="user.username" required>
            </label>
            <div class="padding">
                <button class="button button-block button-stable" ng-click="login()">Login</button>
            </div>
        </ion-content>
    </script>
    

    并且还创建了apps.html template:

    <script type="text/ng-template" id="apps.html">
    
      THIS IS MY APP PAGE
    </script>
    

    最后,要更新路由规则以指向 home.html

      .state('home', {
                    url: '/home',
                    templateUrl: 'home.html',
                    controller: 'HomeCtrl'
                })
    

    【讨论】:

    • 谢谢让我试试我自己
    • 根据本教程,不必输入ui-view。为什么 ?我对这项技术完全陌生,很抱歉提出愚蠢的问题
    • 我已经编辑了我的回复以包含 ui-view 部分
    • 感谢您的回复。为什么添加这一行:&lt;script type="text/ng-template" id="home.html"&gt; 为什么我不能直接从这一行开始:
    • 我使用 templateUrl: 'home.html' 将模板引用到 state.routing 中。因此,该文件应在某处定义。由于我无法轻松地将文件添加到 codepen,因此我添加了一个“模拟”文件的模板。 ui-routing 需要模板来处理状态。你需要阅读更多关于 ui-routing 和 States
    猜你喜欢
    • 1970-01-01
    • 2021-02-23
    • 1970-01-01
    • 2015-08-30
    • 2021-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多