2016-08-01 18 views
0

FehlerSyntax Error & Funktion wurde nicht definiert

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

Ich arbeite eine Cross-Plattform-Anwendung mit Hilfe ionischer Framework Wort Presse als Backend zu erstellen, Im Folgenden sind die Dateien mit den Codes

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'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> 

Antwort

0

Es sieht aus wie Sie den gleichen Controller in Ihrer Konfiguration sowie definieren einen Controller ‚MenuCtrl‘ wiederverwendet werden soll, die innerhalb des html sichtbar ist in der App. In diesem Fall sollten Sie die Funktion besser separat definieren und den Funktionsnamen dort wiederverwenden, wo Sie diese Funktion benötigen. Für z.

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

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

HTH