我在闭包上阅读Mozilla开发者的网站,我在他们的例子中注意到常见的错误,他们有这样的代码:
<p id="help">Helpful notes will appear here</p>
<p>E-mail: <input type="text" id="email" name="email"></p>
<p>Name: <input type="text" id="name" name="name"></p>
<p>Age: <input type="text" id="age" name="age"></p>
Run Code Online (Sandbox Code Playgroud)
和
function showHelp(help) {
document.getElementById('help').innerHTML = help;
}
function setupHelp() {
var helpText = [
{'id': 'email', 'help': 'Your e-mail address'},
{'id': 'name', 'help': 'Your full name'},
{'id': 'age', 'help': 'Your age (you must be over 16)'}
];
for (var i = 0; i < helpText.length; i++) {
var item = helpText[i];
document.getElementById(item.id).onfocus = function() {
showHelp(item.help);
} …Run Code Online (Sandbox Code Playgroud) 我正在开发一个AngularJS应用程序.要在生产中发布代码,我正在使用这个Grunt配置/任务:
grunt.registerTask( 'compile', [
'sass:compile', 'copy:compile_assets', 'ngAnnotate', 'concat:compile_js', 'uglify', 'index:compile'
]);
Run Code Online (Sandbox Code Playgroud)
调试真的很难,对于那些已经遇到过这些问题并且可以指向某个方向的人来说,这是一个问题.
我的主要模块包括那些子模块:
angular
.module('controlcenter', [
'ui.router',
'ui.bootstrap',
'templates-app',
'templates-common',
'authentication',
'api',
'reports',
'interceptors',
'controlcenter.websites',
'controlcenter.users',
'controlcenter.campaigns',
'controlcenter.reports',
'controlcenter.login'
])
.run(run);
Run Code Online (Sandbox Code Playgroud)
我得到的错误如下:
Uncaught Error: [$injector:modulerr] Failed to instantiate module controlcenter due to:
Error: [$injector:modulerr] Failed to instantiate module controlcenter.websites due to:
Error: State 'websites'' is already defined
Run Code Online (Sandbox Code Playgroud)
如果我删除网站模块,我得到controlcenter.users相同的错误.
我正在使用它ui-router来处理应用程序内部的路由.
在我的构建过程(用于集成测试)之后,一切正常:
grunt.registerTask( 'build', [
'clean', 'html2js', 'jshint', 'sass:build',
'concat:build_css', 'copy:build_app_assets', 'copy:build_vendor_assets',
'copy:build_appjs', 'copy:build_vendorjs', 'copy:build_vendorcss', 'index:build', 'karmaconfig',
'karma:continuous'
]);
Run Code Online (Sandbox Code Playgroud)
那么也许 …