Javascript 参数';PeopleController';不是函数,得到未定义的IonicJS 使用IonicJS并呈现一些json细节 获取错误:“参数'PeopleController'不是函数, 没有定义“ 我查过文件了 people_controller.js

Javascript 参数';PeopleController';不是函数,得到未定义的IonicJS 使用IonicJS并呈现一些json细节 获取错误:“参数'PeopleController'不是函数, 没有定义“ 我查过文件了 people_controller.js,javascript,angularjs,ionic-framework,Javascript,Angularjs,Ionic Framework,(功能(){ var app=angular.module('peopleController',[]) app.js: index.html: 离子空白起动器 {{person.name} 我做错了什么?您需要从模块依赖项中删除peopleController===>angular.module('starter',['ionic']) 它是控制器而不是模块 编辑 更改应用程序控制器('PeopleController',…) 通过angular.module('starter')

(功能(){ var app=angular.module('peopleController',[])

app.js:

index.html:


离子空白起动器
  • {{person.name}

我做错了什么?

您需要从模块依赖项中删除
peopleController
===>
angular.module('starter',['ionic'])

它是控制器而不是模块

编辑

更改应用程序控制器('PeopleController',…) 通过
angular.module('starter').controller('PeopleController',…)
也可以

添加Angle文件和PeopleController.js文件

<!-- your app's js -->
<script src="angular/angular.min.js"></script>
<!-- ionic Dependencies ? -->
<script src="js/app.js"></script>
<script src="js/PeopleController.js"></script>

您需要从模块依赖项==>
angular.module('starter',['ionic'])中删除
peopleController

它是控制器而不是模块

编辑

更改应用程序控制器('PeopleController',…)
通过
angular.module('starter').controller('PeopleController',…)
也可以

添加Angle文件和PeopleController.js文件

<!-- your app's js -->
<script src="angular/angular.min.js"></script>
<!-- ionic Dependencies ? -->
<script src="js/app.js"></script>
<script src="js/PeopleController.js"></script>


在应用程序中编译/插入PeopleController模块之前,您正在注入PeopleController模块。请检查JS文件的顺序。加载PeopleController.JS,然后在应用程序中编译/插入PeopleController模块之前,检查JS文件的顺序。加载>PeopleController.js然后app.js

最后的问题是js文件的序列,尝试在PeopleController.js之后加载app.js文件,但没有得到任何结果

angular.module('starter', ['ionic', 'peopleController'])

.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();
    }
  });
})
之后,在加载peopleController.js之后立即加载了app.js,它就像一个符咒一样工作。

  <script src="js/app.js"></script>
  <script src="js/controllers/people_controller.js"></script> 
peopleController.js:

(function() {
var app = angular.module('peopleController', []);

app.controller('PeopleController',
function($scope, $http) {
var url = 'http://localhost:3000/api/people';
$http.get(url)
.success(function(people) {
$scope.people = people;
})
.error(function(data) {
console.log('server side error occurred.'); 
}); 
} 
);
})(); 

最后的问题是在JS文件的序列中,尝试在peopleController.JS之后加载app.JS文件,但没有得到任何结果

之后,在加载peopleController.js之后立即加载了app.js,它就像一个符咒一样工作。

  <script src="js/app.js"></script>
  <script src="js/controllers/people_controller.js"></script> 
peopleController.js:

(function() {
var app = angular.module('peopleController', []);

app.controller('PeopleController',
function($scope, $http) {
var url = 'http://localhost:3000/api/people';
$http.get(url)
.success(function(people) {
$scope.people = people;
})
.error(function(data) {
console.log('server side error occurred.'); 
}); 
} 
);
})(); 

忘记检查html…Edited忘记检查html…Edited我不知道发生了什么事,尝试了你的东西,但没有任何效果。在那之后,我尝试在app.js之后加载peoplecontroller.js,它工作了。我不知道发生了什么事,尝试了你的东西,但没有任何效果。之后,我尝试在app.js之后加载peoplecontroller.js,它工作了。
(function() {
var app = angular.module('peopleController', []);

app.controller('PeopleController',
function($scope, $http) {
var url = 'http://localhost:3000/api/people';
$http.get(url)
.success(function(people) {
$scope.people = people;
})
.error(function(data) {
console.log('server side error occurred.'); 
}); 
} 
);
})();