我收到错误而不是加载controller
。
我提供了我的所有文件,请告诉我们任何错误..
html文件:
<!DOCTYPE html>
<html ng-app="tcpApp">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<base href="/">
<title>TCP App</title>
<link rel="stylesheet" href="css/lib/fonts.css">
<link rel="stylesheet" href="css/lib/reset.css">
<link rel="stylesheet" href="css/tcp.css">
</head>
<body>
<div class="wrapper" ng-view></div>
<!--Libs -->
<script src="js/lib/jquery/dist/jquery.min.js"></script>
<script src="js/lib/angular/angular.min.js"></script>
<script src="js/lib/angular-resource/angular-resource.min.js"></script>
<script src="js/lib/angular-route/angular-route.min.js"></script>
<!--scripts -->
//loading controller as first
<script src="js/script/controllers/homeController.js"></script>
<script src="app.js"></script> //app file
</body>
</html>
app.js:
"user strict";
var tcpAppHolder = angular.module("tcpApp", ["ngRoute"]);
tcpAppHolder
.config(function ($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider
.when ("/home", {
templateUrl : "views/home.html",
controller : "homeController" //loading home controller
});
$routeProvider
.otherwise ({
templateUrl : "views/home.html",
controller : "homeController"
});
});
homecontroller.js文件:
"use strict";
angular.module("tcpApp.controllers")
.controller("homeController", function ($scope) { //but not loading
console.log("i am from home");
});
错误我得到了:
未捕获错误:[$ injector:nomod] http://errors.angularjs.org/1.4.0/ $ injector / nomod?p0 = tcpApp.controllers
答案 0 :(得分:4)
请使用
更新您的家庭控制器angular.module("tcpApp")
.controller("homeController", function ($scope) { //but not loading
console.log("i am from home");
});
导致问题的模块名称不正确。请立即查看。
答案 1 :(得分:2)
您的模块名称为tcpApp
,而不是tcpApp.controllers。编辑homecontroller.js文件。
angular.module("tcpApp")
.controller("homeController", function ($scope) { //but not loading
console.log("i am from home");
});
答案 2 :(得分:2)
需要将tcpApp.controllers添加到tcpAppHolder var。
var tcpAppHolder = angular.module("tcpApp", ["ngRoute", "tcpApp.controllers" ]);