I've noticed a behavior with an angular js application that I've got that I'm trying to fix. The app is using AngularJS 1.6, and I'm able to reproduce this behavior using just html and AngularJS.
Here's my index.html file:
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="js/angular.min.1.6.js"></script>
</head>
<body ng-controller="mainCtrl">
<span>Number:</span><br/>
<span>{{ inputNumber }}</span><br/>
<script type="text/javascript" src="js/application.js"></script>
</body>
</html>
Here's my application.js AngularJS controller file:
(function() {
var app = angular.module("myApp", []);
app.controller("mainCtrl", function ($scope, $http, $location) {
$scope.inputNumber = "";
if ( $location.search().hasOwnProperty( 'number' ) ) {
$scope.inputNumber = $location.search()['number'];
}
});
})();
I've got these two files on my windows workstation desktop in a folder called 'angular app'. I am using the following url to open the index.html file:
file:///C:/Users/myuserid/Desktop/angular%20app/index.html#!/?number=12345
The page that appears is displaying:
Number: 12345
The weird behavior that I'm encountering happens when I change the value assigned to the query string variable 'number':
file:///C:/Users/myuserid/Desktop/angular%20app/index.html#!/?number=56789
After I change the number and click enter, I'm expecting the page to display this:
Number: 56789
But instead it's still displaying this:
Number: 12345
If I click in the address bar, without changing anything, and click enter again, it finally does change to this:
Number: 56789
Why is it that the page doesn't update the first time when I change the value and click enter? Is there anything I can do to fix this?
ng-routeinstead of getting data from the query string may solve your parameter problem.