使用IonicJS并呈现一些json详细信息。
收到错误消息:“参数'PeopleController'不是函数,
    不确定”
我检查了文件
people_controller.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.');
    });
    }
    );
    });


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();
    }
  });
})


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>


    <!-- cordova script (this will be a 404 during development) -->
    <script src="cordova.js"></script>

    <!-- your app's js -->
    <script src="js/app.js"></script>
  </head>
   <body ng-app="starter">

    <ion-pane>
      <ion-header-bar class="bar-stable">
        <h1 class="title">Ionic Blank Starter</h1>
      </ion-header-bar>
      <ion-content>
      <ul class="list" ng-controller="PeopleController">
<li class="item" ng-repeat="person in people">
<h3>{{person.name}}</h3>

</li>
</ul>

      </ion-content>
    </ion-pane>
     <script src="../js/controllers/people_controller.js"></script>

  </body>
</html>


我在做什么错?

最佳答案

您正在注入PeopleController模块,然后再将其编译/插入到您的应用程序中。检查JS文件的顺序。先加载PeopleController.js,然后加载app.js

关于javascript - 参数'PeopleController'不是函数,未定义IonicJS,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36296500/

10-12 00:57