I am currently trying to change my web app from routing through mvc to SPA, where all different will be loaded in single main page. For this I am using ngview directive. This is the main page -
<div ng-app="app">
<div ng-view>
</div>
</div>
@section Scripts{
<script src="~/Scripts/angular-route.js"></script>
<script>
var app=angular.module('app',['ngRoute']);
app.config(function ($routeProvider,$locationProvider) {
$routeProvider
.when("/", {
templateUrl: "Experimental/Index.html",
controller:"AddressList"
})
});
</script>
}
For now I only have one route. my controller is defined in a script tag inside the Index.html file itself and not in a seperate .js file like so -
angular.module('app')
.controller('AddressList', ['$scope', '$http', function ($scope, $http) {
$scope.model = [];
$http.get('/Addresses/GetAddresses').then(function (response) {
if (response != null || response != "undefined") {
$scope.model = response.data;
}
});
}]);
But after load of the main page I am getting an error message -
The controller with name 'AddressList' is not registered.
Does this mean I have to keep all my controllers in seperate files or inside the main html?
templateUrlfiles. All controllers need to be defined before the DOMContentLoaded event.