我的索引文件:爲什麼我的控制器未在以下代碼中註冊?
<!DOCTYPE html>
<html ng-app="myApp" ng-controller="homingController">
<head>
<title></title>
<script src="./js/jquery-1.9.1.js"></script>
<script src="./js/jquery-ui.js"></script>
<script src="./js/angular.js"></script>
<script src="./js/angular-ui-router.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.0/angular-route.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/1.0.3/angular-ui-router.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/1.0.3/angular-ui-router.min.js"></script>
<script src="./Controller/homingController.js"></script>
<link rel = "stylesheet" href = "./css/angular-material.min.css">
<link rel="stylesheet" href="./css/bootstrap-theme.min.css">
<link rel = "stylesheet" href = "./css/materialize.min.css">
<link href="./css/icon.css" rel="stylesheet">
<link rel ="stylesheet" href="./css/Main.css">
<title>Home Application</title>
</head>
<body>
<div class="navbar">
<a href="#/home">Home</a>
<a href="#/monitor">about</a>
</div>
<div ng-view></div>
<script>
var mainApp = angular.module('myApp', ['ngRoute']);
mainApp.config(function($routeProvider) {
$routeProvider.when('/home', {
template: "home",
controller: 'homingController'
})
.when('/monitor', {
template: "<p>{{firstName}}{{lastName}}</p>",
controller: 'monitoringController'
})
.
otherwise({
redirectTo: '/'
});
});
mainApp.controller('monitoringController', ['$scope', function($scope) {
$scope.firstName = "John";
$scope.lastName = "Doe";
}])
我HomingController.js
var mainApp = angular.module('myApp', ['ngRoute']);
mainApp.controller('homingController', ['$scope', function($scope) {
$scope.firstName = "John";
$scope.lastName = "Doe";
}])
我的Home.html代碼:
<div ng-controller="homingController">
{{ lastName }} Hello
</div>
現在我面臨的問題:
1)在homingController,如果我添加了第一行是:
var mainApp = angular.module('myApp', ['ngRoute']);
那麼它給我的錯誤:
angular.js:14328錯誤:[$控制器:ctrlreg]名稱爲「homingController」的控制器未註冊。
1)在homingController,如果我不添加添加第一行是:
var mainApp = angular.module('myApp', ['ngRoute']);
那麼它給我的錯誤:
angular.js:14328錯誤:[$控制器:ctrlreg該名爲'homingController'的控制器未註冊。
謝謝!!
你確定'homingController.js'被正確包含嗎?確保它已加載。 – Red
你能爲這個代碼做一個蹲點嗎? – VicJordan
是它增加了,我可以看到它的源碼 – CodeWithCoffee