0

I'm working with Rails 4 and AngularJS. I've got my app working. Controllers, directives, services, etc. However, my main app.js file refuses to fire the config and run functions. I've got some console.logs in there to test how far it gets. Here's the code:

angular-app/app.js

'use strict';

console.log('we see the app.js file'); // This works

var app = angular.module('bruno', [])

console.log(app) //This works

// This is where is stops working
app.config(function ($httpProvider) {
    alert('config'); // Can't see this
    $httpProvider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content');
})

app.run(function () {
    console.log('App is running'); // Can't see this
});

Like I said, my other controllers are working just fine. The console doesn't show any errors and everything loads just as it should.

Rails application.js file:

//= require angular-app/app
//= require_tree ./angular-app/templates
//= require_tree ./angular-app/modules
//= require_tree ./angular-app/filters
//= require_tree ./angular-app/directives
//= require_tree ./angular-app/models
//= require_tree ./angular-app/services
//= require_tree ./angular-app/controllers

I've re-written this every which way I can think of, but to no avail. I'm kinda stumped. I've done it with and without the var app. Hoping this wonderful community can at least help me see something I can't.


Additional Info

  • I'm using gem 'angular-rails-templates'
  • Rails 4.2.3
  • AngularJS 1.3.16

If you need anything else from me just ask. Who knows, maybe by tomorrow morning I'll see things differently. :-)

1 Answer 1

1

As it turns out, I was mistakenly re-using the same module name inside another controller. Which was overwriting the module name in app.js. All fixed now.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.