I'm having an issue with AngularJS in that there are problems when I reuse variable names across two templates. A simplified version of my setup is as follows, two pages declared in route.js
$routeProvider.when('/a', {
templateUrl: 'a.html'
})
.when('/b', {
templateUrl: 'b.html'
})
each page (a.html
and b.html
) has a script tag like so
<script type="text/javascript">
let foo = 5;
</script>
there is also a navigation menu for navigating between the pages. The issue is that when I go from one page to the other, I get an errror
Uncaught SyntaxError: Identifier 'foo' has already been declared
I know I can just change the variable name, but I want to know why this is happening because my instinct is that it shouldn't be. Am I wrong to be using script tags with Angular? Is this potentially caused by something else? Thanks