, , $routeProvider .
- :
$routeProvider.when(/someModule/page1Condition1, {templateUrl: 'page1.tpl.html', controller: 'page1Ctrl'});
$routeProvider.when(/someModule/page1Condition2, {templateUrl: 'page1.tpl.html', controller: 'page1Ctrl'});
page1 - :
if($location.path()==='/someModule/page1Condition2){
// something that should be done only when Condition2 is true,
// for example, loading data using ajax
$http.get('somePath')
.success(function(data){
$scope.myData = angular.fromJson(data);
});
}
This way, I only have one controller, but conditionally retrieve data using a URL as a source of information. Think of it as wanting to be as close to REST as possible, but not really REST.
It is important to note that I also have some strange requirements imposed by my client, so this is probably not the best way to solve this problem (it may even be antipattern, although I like to think that this is just a temporary hack).
source
share