TypeError:请求的值不是对象的键。 ,Gruntfile,js

时间:2015-01-14 20:47:47

标签: angularjs gruntjs

有人可以告诉我如何解决这个问题,

PhantomJS 1.9.8(Windows 7)ExampleController应查询webservice FAILED         错误:[$ injector:modulerr]由于以下原因导致无法实例化模块TestWebApp:         TypeError:请求的值不是对象的值。

我正在尝试在我的项目中包含角度数据表。

我的Gruntfile.js如下

  module.exports = function (grunt) {

 grunt.loadNpmTasks('grunt-karma');
 grunt.loadNpmTasks('grunt-contrib-jshint');
 grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
 grunt.loadNpmTasks('grunt-jsdoc');

grunt.initConfig({
 'pkg': grunt.file.readJSON('package.json'),
   'meta': {
  'jsFilesForTesting': [
    'bower_components/jquery/dist/jquery.js',
    'js/angular.js',
    'bower_components/angular-route/angular-route.js',
    'bower_components/angular-sanitize/angular-sanitize.js',
    'bower_components/angular-mocks/angular-mocks.js',
    'bower_components/restangular/dist/restangular.js',
    'bower_components/underscore/underscore.js',
    'bower_components/datatables/media/js/jquery.dataTables.js',
    'bower_components/angular-datatables/dist/angular-datatables.js',
    'test/**/*Spec.js'
  ]
},

'karma': {
  'development': {
    'configFile': 'karma.conf.js',
    'options': {
      'files': [
        '<%= meta.jsFilesForTesting %>',
        'source/**/*.js'
      ]
    }
  },
  'dist': {
    'options': {
      'configFile': 'karma.conf.js',
      'files': [
        '<%= meta.jsFilesForTesting %>',
        'dist/<%= pkg.namelower %>-<%= pkg.version %>.js'
      ]
    }
  },
  'minified': {
    'options': {
      'configFile': 'karma.conf.js',
      'files': [
        '<%= meta.jsFilesForTesting %>',
        'dist/<%= pkg.namelower %>-<%= pkg.version %>.min.js'
      ]
    }
  }
},
'jshint': {
  'beforeconcat': ['source/**/*.js']
},

 'concat': {
  'dist': {
    'src': ['source/**/*.js'],
    'dest': 'dist/<%= pkg.namelower %>-<%= pkg.version %>.js'
  }
},

'uglify': {
  'options': {
    'mangle': false
  },  
  'dist': {
    'files': {
      'dist/<%= pkg.namelower %>-<%= pkg.version %>.min.js': ['dist/<%= pkg.namelower %>-<%= pkg.version %>.js']
    }
  }
},
 'jsdoc': {
  'src': ['source/**/*.js'],
  'options': {
    'destination': 'doc'
  }
}

});


 grunt.registerTask('test', ['karma:development']);
grunt.registerTask('build',
[
 'jshint',
  'karma:development',
  'concat',
  'karma:dist',
  'uglify',
  'karma:minified'
]);

};

我的app.js:

var app = angular.module('TestWebApp', [
'ngRoute',
'testControllers',
'testServices',
'datatables'
]);


      app.config(['$routeProvider', function ($routeProvider) {
        $routeProvider
           // Home
      .when("/dashboard", {templateUrl: "partials/package.html", controller: "searchCtrl"})

         // else 404
           .otherwise("/404", {templateUrl: "partials/404.html", controller: "searchCtrl"});
        }]);

最后是控制器:

var controllers = angular.module('testControllers', []);
controllers.controller('ExampleController', function ($scope, UserdataService) {

    UserdataService.getFirstUsername().then(function(firstUsername) {
        $scope.firstUsername = firstUsername;
    }); 

});


  controllers.controller('searchCtrl', function ($scope, DTOptionsBuilder, DTColumnBuilder) {
$scope.message = '';
$scope.someClickHandler = function(info) {
    $scope.message = info.engine + ' - ' + info.platform;
};

$scope.dtOptions = DTOptionsBuilder.fromSource('data/dataTables-objects.json')
    .withPaginationType('full_numbers')
    .withOption('rowCallback', function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
        $('td', nRow).unbind('click');
        $('td', nRow).bind('click', function() {
            $scope.$apply(function() {
                $scope.someClickHandler(aData);
            });
        });
        return nRow;
    });
$scope.dtColumns = [
    DTColumnBuilder.newColumn('engine').withTitle('Engine'),
    DTColumnBuilder.newColumn('browser').withTitle('Browser').notVisible(),
    DTColumnBuilder.newColumn('platform').withTitle('Platform'),
    DTColumnBuilder.newColumn('version').withTitle('Version'),
    DTColumnBuilder.newColumn('grade').withTitle('Grade')
];

});

1 个答案:

答案 0 :(得分:0)

我最终发现javascripts不兼容。这是工作bower.json

 {
  "name": "example",
  "version": "0.0.0",
 "dependencies": {
"angular": "1.2.x",
"angular-route": "1.2.16",
"angular-sanitize": "1.2.16",
"angular-mocks": "1.2.16",
"jquery": "1.8.3",
"underscore": "1.6.0",
"restangular": "1.4.0"
 },
  "analytics": false,
  "resolutions": {
   "angular": ">=1.3.0",
   "jquery": ">=1.11.0"
}
}

我直接从angular-datatables

使用jar数据表

因此我的Gruntfile变为..

 'meta': {
  'jsFilesForTesting': [
    'bower_components/jquery/jquery.js',
    'bower_components/angular/angular.js',
    'bower_components/angular-route/angular-route.js',
    'bower_components/angular-sanitize/angular-sanitize.js',
    'bower_components/angular-mocks/angular-mocks.js',
    'bower_components/restangular/dist/restangular.js',
    'bower_components/underscore/underscore.js',
    'bower_components/underscore/underscore.js',
    'js/jquery/jquery.dataTables.js',
    'js/angular-datatables.js',
    'test/**/*Spec.js'
  ]
},