When the `$location` changes, a simple function is executed as shown below. The issue arises when the assignment of `$location.path().split("/")` returns `["browser"]` for `$location.path() == "/browser"`, but when run directly inside the `console.log`, it returns `["", "browser"]`. How can this discrepancy be logically explained?
angular.module("blah", [])
.controller("navigation", function($scope, $location) {
var updatePage = function() {
var temp = $location.path().split("/");
console.log($location.path(), $location.path().split("/"), temp);
$scope.page = temp.splice(0,1)[0];
$scope.args = temp;
//console.log($scope.page);
};
$scope.changePage = function(path) {
if (path.match("^https?:")) {
window.location = path;
} else {
$location.path(path);
}
};
$scope.args = [];
$scope.$on("$locationChangeSuccess", function(event, data) {
updatePage();
});
updatePage();
});