Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9318165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:02:57+00:00 2026-06-19T03:02:57+00:00

My style of writing angular controllers is like this (using controller name instead of

  • 0

My style of writing angular controllers is like this (using controller name instead of function)

angular.module('mymodule', [
])
    .controller('myController', [
        '$scope',
        function($scope) {
            // Some code here

        }
    ]);

What I need now is when providing i routes I want to define resolve part:

 $routeProvider.when('/someroute', {
        templateUrl: 'partials/someroute.html', 
        resolve: myController.resolve}) // THIS IS THE CRITICAL LINE

Since controller is defined as a name how to accomplish resolve part bellow?

To clarify more in details I want to load some data from server before route is resolved and then use these data in controller.

UPDATE: To be more precise I want each module has its “resolve” function that will be called before root with that controller is executed. Solution in this post (answered by Misko Hevery) does exactly what I want but I don’t have controllers as functions but as a names.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T03:02:58+00:00Added an answer on June 19, 2026 at 3:02 am

    The controller definition and resolve parts are to be specified separately on the route definition.

    If you define controllers on a module level you need to reference them as string, so:

     $routeProvider.when('/someroute', {
            templateUrl: 'partials/someroute.html', 
            controller: 'myController',
            resolve: {
              myVar: function(){
                //code to be executed before route change goes here
              };
            });
    

    The above code also shows how to define a set of variables that will be resolved before route changes. When resolved those variables can be injected to a controller so taking the example from the snippet above you would write your controller like so:

    .controller('myController', ['$scope', 'myVar', function($scope, myVar) {
                // myVar is already resolved and injected here
            }
        ]);
    

    This video might help as well: http://www.youtube.com/watch?v=P6KITGRQujQ

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a website intro page and really like the style on this
I'm writing tools for building games in .NET using functional style. For this, I
I would like to know other people's opinion on the following style of writing
I am currently writing a wizard-style application using Qt4. I am not using the
I am writing a function in C. As a matter of style, when is
I am currently writing a Turret Defense style game using the GTGE engine ,
I often find myself writing very simple classes instead of C-style structs. They typically
I was reading the Writing Style Guidelines provided by Google until I saw this:
I use the following C-ish indentation/bracing style when writing LaTeX code: \foo{ blah blah...
I am writing a wizard-style application in Qt that uses a QStackedWidget to organize

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.