【问题标题】:ionic is not detecting a controllerionic 没有检测到控制器
【发布时间】:2019-02-22 09:54:24
【问题描述】:

我为 ionic v1 创建了一个空白项目,并在 app.js 文件中添加了一个控制器:

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

我还添加了 main.html 文件,它只是一个带有“TEST”文本的空白文件

执行 ionic serve 命令并导航到http://localhost:8100/#/app 控制台命令后未执行,文本未显示。我没有收到任何错误消息。

更新: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 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>

更新:找到解决方案

index.html 缺少 ion-nav-view 标签

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

添加它,一切都开始工作了。

【问题讨论】:

  • 您的index.html 中有什么内容?
  • 控制台日志中有输出吗?
  • @C.Champagne 将 index html 添加到问题中 - 那里没有更改,只是生成了
  • @MurshidAhmed 没有控制台输出。此外,如果我故意在 AppCtrl 中犯了错误 - 没有错误。我认为它只是被 ionic 忽略了

标签: javascript ionic-framework


【解决方案1】:

找到解决方案 index.html 缺少 ion-nav-view 标签

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

添加它,一切都开始工作了。

【讨论】:

    猜你喜欢
    • 2019-04-12
    • 2019-01-30
    • 1970-01-01
    • 2019-09-19
    • 2019-11-11
    • 1970-01-01
    • 2021-06-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多