Синтаксическая ошибка и функция не определены

0

ошибки

controllers.js:6 Uncaught SyntaxError: Unexpected token (
ionic.bundle.js:26794 Error: [ng:areq] Argument 'MenuCtrl' is not a function,  got undefined

Я работаю над созданием кросс-платформенного приложения с помощью Ionic framework с использованием word press в качестве задней части. Ниже приведены файлы с кодами

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>
<script src="lib/ionic-platform-web-client/dist/ionic.io.bundle.min.js"></script>

    <!-- cordova script (this will be a 404 during development) -->
    <!-- Cordova is bootstrapped by ionic-platform-web-client, uncomment this if you remove ionic-platform-web-client... -->
<!-- <script src="cordova.js"></script> -->

    <!-- your app js -->
    <script src="js/app.js"></script>
    <script src="js/controllers.js"></script>
  </head>
  <body ng-app="starter">
        <ion-nav-view> 

        </ion-nav-view>

  </body>
</html>

app.js

// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if(window.cordova && window.cordova.plugins.Keyboard) {
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      // for form inputs)
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

      // Don't remove this line unless you know what you are doing. It stops the viewport
      // from snapping when text inputs are focused. Ionic handles this internally for
      // a much nicer keyboard experience.
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})

.config(function($stateProvider, $urlRouterProvider){
    $stateProvider
        .state('main', {
            url: '/main',
            templateUrl:  'templates/menu.html',
            controller: 'MenuCtrl'
        })

        .state('main.contentRecent', {
            url: '/contentRecent',
            templateUrl:  'templates/menuContent.html',
            controller: 'MenuCtrl'
        })

        .state('main.postDetail', {
            url: '/postDetail',
            templateUrl:  'templates/postDetail.html',
            controller: 'PostCtrl'
        });

        $urlRouterProvider.otherwise('/main/contentRecent');
})

Controllers.js

 angular.module('starter')
 .controller( 'MenuCtrl', function ($http, $scope){
     $scope.categories = [];

     $http.get("http://bijay.sahikura.com/api/get_category_index/").t 
        function(data){

            $scope.categories = data.data.categories;
            console.log(data);

        }, function ( err){
            console.log(err);
        }

})


 .controller('PostCtrl', function() {
     //hello
 })

menu.html

<ion-side-menus> 
    <ion-side-menu-content>
        <ion-nav-view> 

        </ion-nav-view> 

    </ion-side-menu-content>

    <ion-side-menu side="left">
        <ion-header-bar class="bar-stable">
            <h1 class="title"> खुला सरकार  </h1>
        </ion-header-bar> 

        <ion-content>
            <ion-list> 
                <ion-item ng-repeat="category in categories" menu-close  href ="#"> 
                    <span> {{category.title}} </span> <span class="badge badge-assertiv"> १</span> 
                    category.post_count}}</span>
                </ion-item> 
            </ion-list>
        </ion-content> 
    </ion-side-menu>
</ion-side-menus>
Теги:
ionic-framework
cordova

1 ответ

0

Похоже, вы хотите повторно использовать один и тот же контроллер в своей конфигурации, а также определить контроллер 'MenuCtrl', который будет отображаться внутри html в приложении. В этом случае вам лучше определить функцию отдельно и повторно использовать имя функции везде, где вам нужна эта функция. Напр.

function menuCtrlFunc(http, scope) {
  $scope.categories = [];
  // other stuff
}

angular.module('starter').controller('MenuCtrl', menuCtrlFunc);
angular.module('starter').config(
  //....
  //....
  controller: menuCtrlFunc,
);

НТН

Ещё вопросы

Сообщество Overcoder
Наверх
Меню