Take a look at the following code snippet:
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) {...});
If you want to inject either StrategyOne
, StrategyTwo
, or StrategyThree
into MyController
based on the URL, you can consider something like this pseudo-code:
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" });
});
Is there any way to achieve this functionality using AngularJS?