Un travail que j'ai trouvé jusqu'à présent: l'ajout d'une dépendance $ location à mon contrôleur principal révèle que $ location.hash renvoie '' et $ location.path renvoie '/ path # sectionId'.
Sur cette base, nous pouvons ajouter quelque chose comme ce qui suit en haut du contrôleur:
// when has in url is encoded to %23, location.hash does not recognize it, and it gets cleared from the path in $RouteProvider
var holdHash = $location.path();
holdHash = holdHash.split('#');
if (holdHash.length > 1) { // if it has an item after the hash in the array
$location.hash(holdHash.pop()); //take that item and use it as a hash
}
mais vous perdez les valeurs en $ location.search
ou vous pouvez faire ceci:
$location.url(decodeURIComponent($location.url()))
qui conserve également votre recherche, mais remplace '?' avec '% 3F', puis le retourne dans $ location.ash pas $ location.search.
Ils sont un peu hacky une solution en quelque sorte, et ne fonctionnent pas pleinement (voir les problèmes avec le location.search de $)
***** EDIT 2 SOLUTION ****
Comme une solution finale à mon problème, j'ai mis à jour le service qui a stocké l'id, et déclenche la première chose de détection de hachage dans mon contrôleur principal. Également mis à jour la a détection de garder à l'esprit toutes les variations qui qui peuvent être enregistrées:
/**
* tries to get hash from $location
* if unavailable tries to look for encoded hash
* if unavailable returns null
* @return {string or null} [a string with the id of the section or null]
*/
function getHashID() {
var fromLoc = $location.hash(),
fromEncodedUrl,
inPath;
if (fromLoc.length) {
return fromLoc;
}
// iphone Chrome encodes the pound sign on redirect
fromEncodedUrl = $location.url();
fromEncodedUrl = fromEncodedUrl.split('%23');
if (fromEncodedUrl.length > 1) {
return fromEncodedUrl.pop();
}
inPath = $location.path();
inPath = inPath.split('#');
if (inPath.length > 1) {
return inPath.pop();
}
return null;
}
je déclenche plus tard, l'animation avec la valeur stockée dans l'objet de service, ou d'obtenir une nouvelle valeur, et après l'animation est fait je dégage la valeur dans le service.