2015-09-04 62 views
0

在index.html中,我添加了控制器文件的路徑。無法讀取未定義的屬性控制器

我得到這個錯誤與控制器。即使我註釋掉controller.js中的代碼,我仍然會得到這個錯誤。

controller.js

angular.module('starter.controllers', []) 
.controller('AppCtrl', function($scope,$state,$stateParams,$rootScope){ 

}); 

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', 'starter.controllers']) 

.run(function($ionicPlatform) { 
    $ionicPlatform.ready(function() { 
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard 
    // for form inputs) 
    if(window.cordova && window.cordova.plugins.Keyboard) { 
     cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
    } 
    if(window.StatusBar) { 
     StatusBar.styleDefault(); 
    } 
    }); 
}) 
.config(function($stateProvider, $urlRouterProvider) { 
    $stateProvider 
     .state('navBar', { 
     url: "/navBar", 
     abstract: true, 
     templateUrl: "templates/navigationBar.html", 
     controller:'AppCtrl' 

     }) 
     .state('navBar.orderReceive', { 
     url: "/orderReceive", 
     views: { 
      'orderReceiveView': { 
      templateUrl: "templates/OrderReceiveChoice.html" 


      } 
     } 
     }) 

     $urlRouterProvider.otherwise(function ($injector) { 
      var $state = $injector.get('$state'); 
      $state.go('navBar.orderReceive'); 
     }); 

}) 

但我得到一個錯誤 錯誤:

TypeError: Cannot read property 'controller' of undefined 
    at IonicModule.controller.self.update (ionic.bundle.js:51695) 
    at IonicModule.controller.self.beforeEnter (ionic.bundle.js:52135) 
    at IonicModule.controller.self.beforeEnter (ionic.bundle.js:54079) 
    at Scope.$get.Scope.$emit (ionic.bundle.js:24919) 
    at Object.IonicModule.factory.ionicViewSwitcher.create.switcher.emit (ionic.bundle.js:50634) 
    at Object.IonicModule.factory.ionicViewSwitcher.create.switcher.transition (ionic.bundle.js:50492) 
    at ionic.bundle.js:52121 
    at ionic.bundle.js:50370 
    at Object.IonicModule.factory.ionicViewSwitcher.create.switcher.render (ionic.bundle.js:50459) 
    at Object.IonicModule.factory.ionicViewSwitcher.create.switcher.init (ionic.bundle.js:50369)(anonymous function) @ ionic.bundle.js:21157$get @ ionic.bundle.js:17936$get.Scope.$emit @ ionic.bundle.js:24921IonicModule.factory.ionicViewSwitcher.create.switcher.emit @ ionic.bundle.js:50634IonicModule.factory.ionicViewSwitcher.create.switcher.transition @ ionic.bundle.js:50492(anonymous function) @ ionic.bundle.js:52121(anonymous function) @ ionic.bundle.js:50370IonicModule.factory.ionicViewSwitcher.create.switcher.render @ ionic.bundle.js:50459IonicModule.factory.ionicViewSwitcher.create.switcher.init @ ionic.bundle.js:50369IonicModule.controller.self.render @ ionic.bundle.js:52115IonicModule.controller.self.register @ ionic.bundle.js:52073updateView @ ionic.bundle.js:57485IonicModule.directive.compile @ ionic.bundle.js:57469invokeLinkFn @ ionic.bundle.js:17477nodeLinkFn @ ionic.bundle.js:16977compositeLinkFn @ ionic.bundle.js:16368nodeLinkFn @ ionic.bundle.js:16972compositeLinkFn @ ionic.bundle.js:16368nodeLinkFn @ ionic.bundle.js:16972compositeLinkFn @ ionic.bundle.js:16368nodeLinkFn @ ionic.bundle.js:16972compositeLinkFn @ ionic.bundle.js:16368publicLinkFn @ ionic.bundle.js:16243IonicModule.controller.self.appendViewElement @ ionic.bundle.js:52259IonicModule.factory.ionicViewSwitcher.create.switcher.render @ ionic.bundle.js:50449IonicModule.factory.ionicViewSwitcher.create.switcher.init @ ionic.bundle.js:50369IonicModule.controller.self.render @ ionic.bundle.js:52115IonicModule.controller.self.register @ ionic.bundle.js:52073updateView @ ionic.bundle.js:57485(anonymous function) @ ionic.bundle.js:57462$get.Scope.$broadcast @ ionic.bundle.js:24992$state.transitionTo.$state.transition.resolved.then.$state.transition @ ionic.bundle.js:44836processQueue @ ionic.bundle.js:23394(anonymous function) @ ionic.bundle.js:23410$get.Scope.$eval @ ionic.bundle.js:24673$get.Scope.$digest @ ionic.bundle.js:24484$get.Scope.$apply @ ionic.bundle.js:24778done @ ionic.bundle.js:19191completeRequest @ ionic.bundle.js:19363requestLoaded @ ionic.bundle.js:19304 

編輯:按照建議,我改變了這個但我仍然得到相同的錯誤。事實上,如果我刪除整個控制器部分,我仍然會這樣做,如果我有starter.controllers注入app.js

angular.module('starter.controllers', []) 
.controller('AppCtrl', ['$scope', '$state','$stateParams','$rootScope', function($scope,$state,$stateParams,$rootScope){ 
$scope.data = [ 
{name: 'Giani, Pitampura', _id: '01', city:'Delhi'}, 
{name: 'Giani, Rajouri', _id: '02', city:'Delhi'}, 
{name: 'Dominoz, Mayur Vihar ', _id: '03', city:'Delhi'}, 
{name: 'Dominoz, Andheri east', _id: '04', city:'Mumbai'}, 
{name: 'Dominoz, Andheri west', _id: '05', city:'Mumbai'}, 
{name: 'Pizaa planet, west road', _id: '06', city:'Kolkata'}, 
{name: 'Food panda, Gurgaon', _id: '07', city:'Haryana'} 
]; 

$scope.getOutlets=function(cityname){ 
    console.log("called") 
    $scope.outlets = data.map(function(obj){ 
    return obj.city === cityname 
    }) 

} 
}]); 

編輯2:

我才意識到,我莫名其妙地收到因爲嵌套這種狀態。如果我使狀態爲非抽象並附加控制器,那麼它工作正常。如何在不存在此問題的情況下保留嵌套狀態?

回答

1

看看下面你的答案參考,看起來你是不是使用扶養陣列符號正常。

Reference link

相關問題