Mon fichier d'index:Pourquoi mon contrôleur n'est pas enregistré dans le code ci-dessous?
<!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";
}])
Mes HomingController.js
var mainApp = angular.module('myApp', ['ngRoute']);
mainApp.controller('homingController', ['$scope', function($scope) {
$scope.firstName = "John";
$scope.lastName = "Doe";
}])
Mon code Home.html:
<div ng-controller="homingController">
{{ lastName }} Hello
</div>
Maintenant, je suis face à problème:
1) En homingController, si j'ajoute la première ligne qui est la suivante:
var mainApp = angular.module('myApp', ['ngRoute']);
il me donne l'erreur:
angularjs: 14328 Erreur: [$ controller: ctrlreg] Le contrôleur avec le nom 'homingController' n'est pas enregistré.
1) Dans homingController, si je n'ajouter ajouter la première ligne qui est la suivante:
var mainApp = angular.module('myApp', ['ngRoute']);
il me donne l'erreur:
angularjs: 14328 Erreur: [$ controller: ctrlreg] Le Le contrôleur avec le nom 'homingController' n'est pas enregistré.
merci !!
Etes-vous sûr que 'homingController.js' est correctement inclus? Assurez-vous que c'est chargé. – Red
pouvez-vous faire un plunker pour ce code? – VicJordan
Oui son ajouté et je peux le voir dans la source ainsi – CodeWithCoffee