<html>
<head>
<title>Test</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="angular.js"></script>
</head>
<body ng-app="">
<p>There {{count = 1; (count == 1 ? "is" : "are")}} one of them</p>
<div ng-init="count = 7; unit = 'days'; collection = 'week'">
<p>
There are {{count}} {{unit}} in a {{collection}}.
</p>
</div>
</body>
</html>
Within this code snippet, the variable count
is initially set to 1
and then reassigned to 7
, but the displayed result is as follows:
There is one of them
There are 1 days in a week.
This unexpected behavior raises the question of why the global scope precedence rule is not being followed? Shouldn't the last assigned value be displayed instead?