考虑代码:
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) {...});
根据 URL,我StrategyOne
希望StrategyTwo
在StrategyThree
构造MyController
. 一个伪代码来说明这个想法:
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" });
});
我可以用AngularJS实现这样的改变吗?