【问题标题】:ionic $scope.go not working on deviceionic $scope.go 在设备上不起作用
【发布时间】:2015-05-17 21:55:33
【问题描述】:

已经用空白模板在最新的 ionic 上配置了一个新项目

$state.go('post.request');在 LoginCtrl 中的浏览器中工作,但不是当我在手机上运行时(S4 android 5.0)

检查了 logcat 是否有任何错误,但它是干净的。

这是模板

<div class="bar bar-header bar-assertive">
  <h1 class="title">HRC Karaoke</h1>
</div>

<div class="list padding has-header">
    <button class="button button-stable fullwidth" ng-click="checkLogin();">
      Login with Facebook
    </button>
</div>

控制器

angular.module('hrc.controllers', [])

    .controller('LoginCtrl', function ($scope, $state) {
        $scope.checkLogin = function () {
            $state.go('post.request');
        };
    })
    .controller('RequestCtrl', function ($scope) {
        console.log("request");
    });

还有应用文件

angular.module('hrc', ['ionic', 'hrc.controllers', 'ui.router'])
    .run(function ($rootScope, $state) {
    })

    .config(function ($stateProvider, $urlRouterProvider, $stateProvider) {
        $stateProvider
            .state('pre', {
                url: "/pre",
                abstract: true,
                views: {
                    'main': {
                        templateUrl: "t/pre/pre.html",
                        controller: "StartCtrl"
                    }
                }
            })
            .state('pre.login', {
                url: "/login",
                views: {
                    'preContent': {
                        templateUrl: "t/pre/login.html",
                        controller: "LoginCtrl"
                    }
                }
            })
            .state('post', {
                url: "/post",
                abstract: true,
                views: {
                    'main': {
                        templateUrl: "t/post/post.html",
                        controller: "PostCtrl"
                    }
                }
            })
            .state('post.request', {
                url: "/request",
                views: {
                    'postContent': {
                        templateUrl: "/t/post/request.html",
                        controller: "RequestCtrl"
                    }
                }
            })
        $urlRouterProvider.otherwise('/pre/login');
    });

【问题讨论】:

  • checklogin 函数被触发了吗?

标签: android cordova angular-ui-router ionic-framework ionic


【解决方案1】:

您的模板 URL 必须是相对的:

"/t/post/request.html" => "t/post/request.html"

此处说明:

Using Angular UI-Router with Phonegap

【讨论】:

  • 你是在问还是答案?
  • 哇这工作! ...所以我猜 urls 必须是相对的,因为在浏览器环境中,root 来自 www,但在应用程序中它的级别更高?
猜你喜欢
  • 2015-08-12
  • 2017-07-12
  • 1970-01-01
  • 2015-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多