Elio Chamy
Elio Chamy

Reputation: 269

Could not resolve 'state' from state ''

I am new to ionic, I was trying to navigate to another page using this code :

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

});

I don't know where the problem is, I tried to search, didn't find any working solution. I verified the injectors, I tried the $location. Nothing is working.

Any idea?

Upvotes: 1

Views: 249

Answers (2)

coder
coder

Reputation: 8702

try to initialize routes from outside of the controller like below.

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

});

Upvotes: 1

federico scamuzzi
federico scamuzzi

Reputation: 3778

you forget to put the directive (ui-view) where template can be injected .. something like:

<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>

Upvotes: 0

Related Questions