【问题标题】:Could not resolve 'state' from state ''无法从状态“”解析“状态”
【发布时间】:2017-02-26 19:10:06
【问题描述】:

我是 ionic 新手,我试图使用此代码导航到另一个页面:

HTML index.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">
    <script src="lib/ionic/js/ionic.bundle.js"></script>
    <script src="cordova.js"></script>
    <script src="js/app.js"></script>
  </head>
  <body ng-app="Humanity" ng-controller="main">



      <div style="with:100%;">
      <img src="img/loginlogo.png" style="display:block;margin:0 auto;">
      </div> <br>
<div class="list">
  <label class="item item-input item-floating-label">
    <span class="input-label">Email</span>
    <input type="text" placeholder="First Name">
  </label>
  <label class="item item-input item-floating-label">
    <span class="input-label">Password</span>
    <input type="text" placeholder="Last Name">
  </label>

</div>
<button ng-click="test();" class="button button-block  icon-right ion-chevron-right button-balanced" style="width:90%;display:block;margin:0 auto;">
  Sign in
 </button><br>

 <button class="button button-block icon-right ion-chevron-right button-positive" style="width:90%;display:block;margin:0 auto;">
  Register
</button>

  </body>
</html>

js app.js:

var app = angular.module('Humanity', ['ionic']);
app.controller('main', function ($scope,$state, $ionicModal, $location) { 
var route = angular.module('route', ["ui.router"]);
app.config(function($stateProvider, $urlRouterProvider) {

  $stateProvider
    .state('home1', {
      url: "templates/home1",      
      templateUrl: "templates/test.html"

    })


});
$scope.test = function() {
  $state.go('home1');
};

});

我不知道问题出在哪里,我试图搜索,没有找到任何可行的解决方案。我验证了喷油器,我尝试了 $location。没有任何效果。

有什么想法吗?

【问题讨论】:

  • 嗨..我想你忘记了模板可以注入的地方..比如: ...或其他类型(取决于你模板和路由

标签: html angularjs ionic-framework


【解决方案1】:

尝试从控制器外部初始化路由,如下所示。

var app = angular.module('Humanity', ['ionic']);

app.config(function($stateProvider, $urlRouterProvider) {

  $stateProvider
    .state('home1', {
      url: "templates/home1",
      templateUrl: "templates/test.html"

    })


});

app.controller('main', function($scope, $state, $ionicModal, $location) {

  $scope.test = function() {
    $state.go('home1');
  };

});

【讨论】:

    【解决方案2】:

    您忘记将指令(ui-view)放在可以注入模板的位置......类似:

    <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">
        <script src="lib/ionic/js/ionic.bundle.js"></script>
        <script src="cordova.js"></script>
        <script src="js/app.js"></script>
      </head>
      <body ng-app="Humanity" ng-controller="main">
    
    
    
          <div style="with:100%;">
          <img src="img/loginlogo.png" style="display:block;margin:0 auto;">
          </div> <br>
    <div class="list">
      <label class="item item-input item-floating-label">
        <span class="input-label">Email</span>
        <input type="text" placeholder="First Name">
      </label>
      <label class="item item-input item-floating-label">
        <span class="input-label">Password</span>
        <input type="text" placeholder="Last Name">
      </label>
    
    </div>
    <button ng-click="test();" class="button button-block  icon-right ion-chevron-right button-balanced" style="width:90%;display:block;margin:0 auto;">
      Sign in
     </button><br>
    
     <button class="button button-block icon-right ion-chevron-right button-positive" style="width:90%;display:block;margin:0 auto;">
      Register
    </button>
    
    <ui-view></ui-view> <!-- // HERE IS INJECTED YOUR TPL -->
      </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2015-03-31
      • 2017-08-24
      • 1970-01-01
      • 1970-01-01
      • 2015-04-28
      • 1970-01-01
      • 2015-10-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多