简体   繁体   English

如何在“ angular.module”文件中“导入” controller.js文件

[英]How to “import” a controller.js file in the angular.module file

I'm just starting to learn Angular so the issue I'm trying to figure out here might be a bit awkwardly formulated. 我刚刚开始学习Angular,所以我想在这里解决的问题可能有点尴尬。 I'll try my best and explain what I'm dealig with. 我会尽力并解释我要处理的内容。

I have a main main.js module file where I have declared 我有一个主main.js模块文件,在该文件中已声明

angular.module('app', [
'ngRoute'

]) ])

Now I have a separrate file for the controller as home.controller.js which contains 现在我有一个单独的控制器文件,如home.controller.js,其中包含

angular
.module('app')    
.controller('HomeController', ['$scope', function($scope) {
}]);

Is there any way to include the home.controller.js file withing the main.js file without having to put the script src in the html ? 有什么方法可以将home.controller.js文件与main.js文件一起包含,而不必将src脚本放入html中吗? I have tried to import 'path/home.conntroller.js but I get this error 我尝试import 'path/home.conntroller.js但出现此错误

Module 'app' is not available! 模块“ app”不可用! You either misspelled the module name or forgot to load it. 您可能拼错了模块名称,或者忘记了加载它。

Appreciate the help. 感谢帮助。

Make sure main.js is included in your HTML file before home.controller.js ... for example: 确保在home.controller.js之前的HTML文件中包含main.js,例如:

 <script src="main.js"></script> <script src="home.controller.js"></script> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM