2016-08-01 21 views
0

エラー構文エラー&機能が未定義

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

を得た私は、バックエンドとしてワードプレスを使用してイオン性の枠組みの助けを借りて、クロスプラットフォームのアプリケーションを作成するために働いて、後はコード

インデックス付きファイルです。 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's 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> 

答えて

0

あなたが設定内の同じコントローラを再利用するだけでなく、HTMLの中に表示されているコントローラ「によりMenuCtrl」を定義したいように見えます アプリでその場合、関数を別々に定義し、その関数が必要な場所で関数名を再利用するほうがよいでしょう。たとえば。

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

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

HTH

関連する問題