将angular js应用程序index.html页面设置为只包含一个控制器

setup angular js application index.html page to include only singe controller

本文关键字:包含一 控制器 页面设置 html angular js 应用程序 index      更新时间:2023-09-26

我在后端使用nodejs编写了一个角度应用程序(MEAN(。应用程序中有多个模块,因此有多个控制器。

我们必须在index.html文件中包括所有的控制器,如果我们添加到任何模块中,也必须包括新的控制器。

我已经检查了在同一堆栈上运行的其他应用程序(MEAN(,但在那里的源代码中我还没有找到所有的控制器。

所以请帮助我优化我的应用程序。

那么我建议研究Gulp,因为它可以连接,如果你想的话,可以缩小你的代码库并将其放在一个文件中。然后可以在index.html 中引用该单个文件

// Example - Concate the js files together and place them in the dist folder
gulp.task('js', function(){
  var src = ['../../file-name.js'];
  return gulp.src(src)
    .pipe(concat('main.js').on('error', gutil.log))
    .pipe(gulp.dest('dist/js').on('error', gutil.log))
});

这是我与Angular1合作时使用的示例。Gulp将我的所有目标文件放在dist文件夹和index.html文件中引用的main.js文件中。

 <script type="text/javascript" src="js/main.js"></script>