Angular: Empty Fiddle
http://angularjs.org/
by ibsenvalath
HTML
<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-controller="MyCtrl">
<div ng-view></div>
</div>
<script type="text/ng-template" id="test.html">
<div ng-click="loadTemplate(1)">Link 1</div>
<div ng-click="loadTemplate(2)">Link 2</div>
<div ng-include="dynamicTemplate"></div>
</script>
<script type="text/ng-template" id="1.html">
ID 1 contents loaded
</script>
<script type="text/ng-template" id="2.html">
ID 2 contents loaded
</script>
JavaScript
var myApp = angular.module('myApp', []);
myApp.config(['$routeProvider', function ($routeProvider) {
$routeProvider.when("/test", {
templateUrl: "test.html",
controller: "testCtrl",
reloadOnSearch: false
});
}]);
function MyCtrl($scope,$location) {
$location.path('/test');
}
function testCtrl($scope, $location) {
$scope.dynamicTemplate = '1.html';//default template
alert("Loading controller with id: " + $location.search().id);
$scope.loadTemplate = function(linkid){
$location.search('id', linkid);
$scope.dynamicTemplate = (linkid)+'.html';
//$scope.$apply();
}
}