0
我很新的angularjs。我正在用browserify开发应用程序。需要角度与browserify
当我用require
只是字符串,它的工作。但是当我将它与一些组合的字符串一起使用时,它不起作用。
我的意思是require('./todo')
正在工作,但var todo = 'todo'; require('./' + todo)
不是。
问题代码index.js在这里。
var fs = require('fs');
var files = fs.readdirSync(__dirname);
var controllers = module.exports = {};
// files.length is 2 and the names are index.js and todo.js
for (var i=0; i<files.length; i++) {
var file = files[i];
if (file !== 'index.js') {
var fileName = file.split('.')[0];
var modulePath = './' + fileName;
// below code is working.
controllers[fileName] = require('./todo');
// below code is not working. The error code -> Uncaught Error: Cannot find module './todo'
controllers[fileName] = require(modulePath);
}
}
什么问题?