0

I have this angular app that I am running off only one webpage of my site. I have a main application that uses another module I made as a dependency.

The problem I am having is that nothing inside my controller is being ran. Why won't my controller run?

My route does bring in the view however so I know that the module is working. I got rid of my data service to be certain that it was not it. The console.log before the function outputs, but nothing in the function runs. I also have no console errors.

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 am wondering if it has something to do with bootstrapping my application? (But it all still works even without the explicit ng-app, so I am thinking that my bootstrapping does work)

My next best guess is that my controller in my html is not being set correctly, but every time I mess with it I either get the same result or an error in the console, and it still doesn't work.

1
  • Just a heads up, I removed a bunch of the spaces and html that had nothing to do with the actual issue at hand. Makes it a little easier to read through for anyone that comes across this issue in the future. Commented Apr 26, 2016 at 4:02

1 Answer 1

1

blogController.$inject = ['$scope','blogController']

you're trying to inject your controller into your controller. Change it to blogController.$inject = ['$scope'] and function blogController($scope).

Did you mean to write? blogController.$inject = ['$scope','blogContent']

I see you're calling a method on blogContent and I don't see it injected anywhere.

Edit

data-ngController should be data-ng-controller.

Sign up to request clarification or add additional context in comments.

8 Comments

I did that just messing around. I don't have it anymore and it is still not working. I'll update my code here, maybe I messed something up reverting it.
@KyleCalica-St update your code to reflect it's current state then, please.
OMG, once again I didn't catch it. I swear this is the second time I did this and posted to stackoverflow. You are a savior @Yatrix thank you!
@KyleCalica-St We've all been there. Sometimes it just takes another set of eyeballs.
sidenote: does this question really deserve a -1? I posted after doing my own research and had all my code and my tries documented. Small mistake surely, but do you downvote for missing something like that? I'm not pissed I'm legitimately asking
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.