TypeError: Requested keys of a value that is not an object. , Gruntfile,js
TypeError: Requested keys of a value that is not an object. , Gruntfile,js
有人可以告诉我如何解决这个问题,
PhantomJS 1.9.8 (Windows 7) ExampleController 应该查询 web 服务失败
错误:[$injector:modulerr] 由于以下原因无法实例化模块 TestWebApp:
类型错误:请求的键值不是对象。
我正在尝试在我的项目中包含 angular-数据表。
我的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')
];
});
我最终发现 javascript 不兼容。这里正在工作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'
]
},
有人可以告诉我如何解决这个问题,
PhantomJS 1.9.8 (Windows 7) ExampleController 应该查询 web 服务失败 错误:[$injector:modulerr] 由于以下原因无法实例化模块 TestWebApp: 类型错误:请求的键值不是对象。
我正在尝试在我的项目中包含 angular-数据表。
我的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')
];
});
我最终发现 javascript 不兼容。这里正在工作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'
]
},