I have the following HTML+Angular app shell that does everything I need it to do:
#/
.view
variable is updated.This much works perfectly:
<!DOCTYPE html>
<html ng-app>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.js"></script>
<script>
function Router($scope) {
if (location.hash === "") location.hash = "#/";
$scope.view = createView(location);
window.addEventListener("hashchange", function (event) {
$scope.view = createView(event.newURL);
$scope.$apply();
});
}
function createView(url) {
var parser = document.createElement("a");
parser.href = url.toString();
var hash = parser.hash;
return (hash.replace("#/", "/views/") + "/index.html").replace("//", "/");
}
</script>
</head>
<body ng-controller="Router">
Navigation:
<a href="#/one/">one</a>
<a href="#/two/">two</a>
Partial: {{view}}
<!--<div ng-include="view"></div>-->
</body>
</html>
Then only problem is that as soon as I uncomment the div[ng-include]
, everything stops working. Specifically, the hashchange
events stop firing. Am I doing something wrong or is this a bug? Any workarounds?