I have encountered an issue with my Angular app where nothing inside my controller seems to be running. This app is hosted on a single webpage of my site and has a main application that relies on another module I created as a dependency.
Despite the fact that my route successfully brings in the view, the controller fails to execute. Why is my controller not running?
I have ruled out my data service as the culprit after removing it from the equation for testing purposes. The console.log statement before the function is called does output, however, none of the code within the function executes. Additionally, there are no console errors present.
Here is a snippet of my app.js:
(function(){
'use strict';
var dependencies = [
'ghpg',
'ngRoute'
];
angular.module('blogger', dependencies)
.config(Config);
Config.$inject = ['$locationProvider']
function Config($locationProvider){
$locationProvider.hashPrefix('!');
}
if (window.location.hash === '#_=_'){
window.location.hash = '#!';
}
//bootstrap angular
angular.element(document).ready(function(){
angular.bootstrap(document, ['ghpg']);
});
})();
module:
(function(){
'use strict';
var dependencies = [ 'ngRoute' ];
angular.module('ghpg', dependencies)
.run(init)
init.$inject = ['$rootScope','$location' ];
function init($rootScope, $location){
var vm = this;
}
})();
View:
<div class="container-fluid" data-ngController="blogController as vm">
<h2> Articles </h2>
<div class="post-listing" data-ng-repeat=" post in vm.data">
<p> {{ post }} </p>
</div>
</div>
Controller: (function(){ 'use strict';
angular
.module('ghpg')
.controller('blogController', blogController);
blogController.$inject = ['$scope'];
////
console.log("In controller file");
function blogController($scope){
console.log('running controller');
var vm = this;
vm.data = blogContent.getContent();
console.log(vm.data);
}
})();
I suspect the issue could possibly be related to the way my application is being bootstrapped. However, everything still functions even without explicitly defining ng-app, leading me to believe that the bootstrap process is functioning correctly.
Another consideration is that my controller setup in the HTML might be incorrect. Despite experimenting with different configurations, the result remains unchanged or results in a console error, and the problem persists.