Markus
Markus

Reputation: 213

ionic is not detecting a controller

I created a blank project for ionic v1 and added a controller inside app.js file:

angular.module('starter', ['ionic'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if (window.cordova && window.Keyboard) {
      window.Keyboard.hideKeyboardAccessoryBar(true);
    }

    if (window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})


.config(function($stateProvider){

    $stateProvider

    .state('app', {
        url: '/app',
        templateUrl: 'main.html',
        controller: 'AppCtrl',  
    })
})

.controller('AppCtrl',function($scope){
    console.log("test");
})

Also I added main.html file, which is just a blank file with "TEST" text

After executing ionic serve command and navigating to http://localhost:8100/#/app console command is not executed, and text isn't shown. I receive no error messages.

UPDATE: index.html file

<!DOCTYPE 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="starter">

    <ion-pane>
      <ion-header-bar class="bar-stable">
        <h1 class="title">Ionic Blank Starter</h1>
      </ion-header-bar>
      <ion-content name="content">
      </ion-content>
    </ion-pane>
  </body>
</html>

UPDATE: Found a solution

index.html was missing ion-nav-view tags

  <body ng-app="starter">
    <ion-nav-view></ion-nav-view> 
  </body>

Added it and everything started to work.

Upvotes: 0

Views: 107

Answers (1)

Markus
Markus

Reputation: 213

Found a solution index.html was missing ion-nav-view tags

  <body ng-app="starter">
    <ion-nav-view></ion-nav-view> 
  </body>

Added it and everything started to work.

Upvotes: 1

Related Questions