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 8722627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:27:20+00:00 2026-06-13T07:27:20+00:00

Consider the code: var app = angular.module(app, [], function($routeProvider) { $routeProvider .when(/page1, { controller:

  • 0

Consider the code:

var app = angular.module("app", [], function($routeProvider) {
  $routeProvider
    .when("/page1", { controller: "MyController" })
    .when("/page2", { controller: "MyController" })
    .when("/page3", { controller: "MyController" });
});

app.factory("StrategyOne", function() {...});
app.factory("StrategyTwo", function() {...});
app.factory("StrategyThree", function() {...});

app.controller("MyController", function(Strategy, $scope) {...});

Depending on URL, I want either StrategyOne, or StrategyTwo, or StrategyThree to be injected, when constructing MyController. A pseudo-code to illustrate the idea:

var app = angular.module("app", [], function($routeProvider) {
  $routeProvider
    .when("/page1", { controller: "MyController", Strategy: "StrategyOne" })
    .when("/page2", { controller: "MyController", Strategy: "StrategyTwo" })
    .when("/page3", { controller: "MyController", Strategy: "StrategyThree" });
});

Any change I can achieve something like this with AngularJS?

  • 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-13T07:27:21+00:00Added an answer on June 13, 2026 at 7:27 am

    Yes! AngularJS can handle this pretty easily thnx to the resolve property of a route definition (more info here).

    So, basically you could write something like:

    var app = angular.module("app", [], function($routeProvider) {
      $routeProvider
        .when("/page1", { controller: "MyController", resolve: {Strategy: "StrategyOne"}})
        .when("/page2", { controller: "MyController", resolve: {Strategy: "StrategyTwo"}})
        .when("/page3", { controller: "MyController", resolve: {Strategy: "StrategyThree"}});
    });
    

    to have the proper strategy injected into your controller! AngularJS DI at its best!

    There is a very good video tutorial dealing with the resolve topics, you might find it interesting: http://www.youtube.com/watch?v=P6KITGRQujQ&list=UUKW92i7iQFuNILqQOUOCrFw&index=4&feature=plcp

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

Sidebar

Related Questions

Consider this code... var org = {}; org.Organization = function() { var app =
Consider this code: var img = new Image(); img.onload = function() { console.log(this.width); };
Consider the code: window.a = function(x){ var r = x*2; window.a =alert; // redefines
Consider this (rather pointless) javascript code: function make_closure() { var x = 123, y
Let's consider this code: (function(){ var a = {id: 1, name: mike, lastname: ross};
Consider this piece of code var crazy = function() { console.log(this); console.log(this.isCrazy); // wrong.
Consider the following Javascript code: var a = []; var f = function() {
Consider the following code var myData = {name: 'John'}; function fixName(data) { var newData
Consider the following Java script code: var myObj = function ( ) { var
Consider the following code: var table = function () { return { _init: function

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.