Ainda não tem acesso? Estude com a gente! Matricule-se
Ainda não tem acesso? Estude com a gente! Matricule-se

Solucionado (ver solução)

Error: [$compile:ctreq] Controller 'ionNavBar', required by directive 'ionNavTitle', can't be found!

erro apresentado no console Chrome:

Error: [$compile:ctreq] Controller 'ionNavBar', required by directive 'ionNavTitle', can't be found!
http://errors.angularjs.org/1.5.3/$compile/ctreq?p0=ionNavBar&p1=ionNavTitle
    at ionic.bundle.js:13438
    at getControllers (ionic.bundle.js:22473)
    at nodeLinkFn (ionic.bundle.js:22375)
    at compositeLinkFn (ionic.bundle.js:21703)
    at nodeLinkFn (ionic.bundle.js:22387)
    at compositeLinkFn (ionic.bundle.js:21703)
    at publicLinkFn (ionic.bundle.js:21583)
    at Object.self.appendViewElement (ionic.bundle.js:59907)
    at Object.render (ionic.bundle.js:57893)
    at Object.init (ionic.bundle.js:57813)

index.html

<!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 href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/ionic.app.css" rel="stylesheet">
    -->

    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>

    <!-- cordova script (this will be a 404 during development) -->
    <script src="cordova.js"></script>

    <!-- your app's js -->
    <script src="js/app.js"></script>
    <script src="js/controller.js"></script>
    <script src="js/routes.js"></script>
  </head>


  <body ng-app="starter" ng-controller="ListagemController">

    <ion-pane>
      <ion-header-bar class="bar-stable">
        <h1 class="title">Alura Car </h1>
      </ion-header-bar>
      <ion-nav-view></ion-nav-view>
      <ion-footer-bar class="bar-stable">
        <h1 class="title"> Rua Vergueiro, 3185 </h1>
      </ion-footer-bar>

    </ion-pane>
  </body>
</html>

controller.js

angular.module('starter')
.controller('ListagemController',function($scope){

$scope.listaDeCarros = ['BMW 120i', 'Onix 1.6', 'Fiesta 2.0', 'C3 1.0', 'Uno Fire', 'Sentra 2.0', 'Vectra 2.0 Turbo', 'Hilux 4X4', 'Montana Cabine Dupla', 'Outlander 2.4','Fusca 1500'];

});

angular.module('starter')
.controller('CarroEscolhidoController',function(){


});

listagem.html

<ion-view>
    <ion‐nav‐title>Alura car</ion‐nav‐title>
    <ion-content>
            <ion-list>
              <ion-item ng-repeat="carro in listaDeCarros" href="#/carroescolhido">
                {{carro}}
            </ion-list>
    </ion-content>
</ion-view>

routes.js

angular.module('starter')
.config(function($stateProvider, $urlRouterProvider){

    $urlRouterProvider.otherwise('listagem');

    $stateProvider

    .state('listagem',{
        url:'/listagem',
        templateUrl:'templates/listagem.html',
        controller:'ListagemController'
    })

    .state('carroescolhido',{
        url:'/carroescolhido',
        templateUrl:'templates/carroescolhido.html',
        controller: 'CarroEscolhidoController'
    })


})

carroescolhido.html

<ion-view>
    <ion-nav-title>Carro escolhido</ion-nav-title>
    <ion‐content>
        <div class="card">

        </div>
    </ion‐content>

</ion-view>
2 respostas
solução

O problema está na index, a view não está achando o ion-nav-bar, onde aparece o nome da página e o botão de voltar. Ele é exibido no topo da página.

Você precisa inserir ele dentro do ion-nav-view. Segue exemplo:

<!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 href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/ionic.app.css" rel="stylesheet">
    -->

    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>

    <!-- cordova script (this will be a 404 during development) -->
    <script src="cordova.js"></script>

    <!-- your app's js -->
    <script src="js/app.js"></script>
    <script src="js/controllers.js"></script>
    <script src="js/routes.js"></script>


  </head>
  <body ng-app="starter" ng-controller="ListagemController">
    <ion-pane>
      <ion-nav-view>
        <ion-nav-bar class="bar bar-positive">
          <ion-nav-back-button></ion-nav-back-button>
        </ion-nav-bar>
      </ion-nav-view>

      <ion-footer-bar class="bar-stable">
        <h1 class="title">Rua Vergueiro, 3185</h1>
      </ion-footer-bar>
    </ion-pane>
  </body>
</html>

Obrigado!!!

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software