yeoman angular not not views

时间:2015-06-27 08:54:12

标签: javascript angularjs yeoman hapijs

所以,我一直试图使用Yeoman的官方角色和this hapijs generator为后端设置应用程序。现在,到目前为止,在后端我只能获得为index.html服务的主路由,你可以在这里看到

  server.route({
    method: "GET",
      path: "/{param*}",
      handler: {
        directory: {
          path: ["../../client/app", "../../client/bower_components"]
        }
      },
      config: {
      auth: false
    }
  });

  next();
};

exports.register.attributes = {
  name: 'index'
};

直到我尝试向角度应用程序添加新服务,控制器和视图时才能工作,当我这样做时,视图停止渲染。

继承人的服务:

angular.module('graphMeDota2App', [])
  .service('MatchesService', ['$httpq', 'config', function ($httpq, config) {
    // AngularJS will instantiate a singleton by calling "new" on this function
    return {
        GetAllMatches: function(){
            return $httpq.get(config.steamApiBaseUrl + 'IDOTA2Match_570/GetMatchHistory/v001/?key' + config.steamApiKey + '&accountId' + config.steamAccountId + '&matches_requested=5');
        }
    };
  }]);

继承人:

angular.module('graphMeDota2App')
  .controller('MatchesCtrl', ['MatchesService', function ($scope, MatchesService) {
        $scope.matches = {};

        $scope.getMatches = function(){
            MatchesService.GetAllMatches().done(function(response){
                $scope.matches = response.data;
            });
        };

        $scope.getHeroPlayed = function(match){
            console.log(match);
            return 'asdfasdf';
        };
  }]);

继承人的观点:

<div class="jumbotron">
  <table>
    <tr>
      <th>Number</th>
      <th>Match Id</th>
    </tr>
    <tr ng-repeat="match in matches">
      <th>{{$index}}</th>
      <th>{{match.match_id}}</th>
    </tr>
  </table>
</div>

这是我的app.js:

angular
  .module('graphMeDota2App', [
    'ngAnimate',
    'ngCookies',
    'ngResource',
    'ngRoute',
    'ngSanitize',
    'ngTouch'
  ])
  .config(function ($routeProvider) {
    $routeProvider
      .when('/', {
        templateUrl: 'views/main.html',
        controller: 'MainCtrl'
      })
      .when('/about', {
        templateUrl: 'views/about.html',
        controller: 'AboutCtrl'
      })
      .when('/matches', {
        templateUrl: 'views/matches.html',
        controller: 'MatchesCtrl'
      })
      .otherwise({
        redirectTo: '/'
      });
  });

最后,this is what I get:

在添加我的控制器/服务(都添加了yeoman命令行生成器)之前,没有javascript错误,没有服务器端错误,并且视图呈现完美。

1 个答案:

答案 0 :(得分:0)

所以,按照Byron Sommardahl的说法发现问题是我创建服务的时候,特别是这一行:

angular.module('graphMeDota2App', [])
  .service('MatchesService', ['$httpq', 'config', function ($httpq, config) {

我唯一做的就是删除第一个&#34; []&#34;在第一行,然后它开始工作。有关为何发生这种情况的任何想法?

angular.module('graphMeDota2App')
      .service('MatchesService', ['$http', 'config', function ($http, config) {