0
**This works:**
<script src="Scripts/angular.js"></script>
**But not this one:**
<script src="~/Scripts/angular.js"></script>

Can anyone explain why the second one not's working?

JJJ
  • 93
  • 2
  • 16
  • ~ is referring to the root directory, similar to the explaination here https://stackoverflow.com/questions/6424114/slash-vs-tilde-slash-in-style-sheet-path-in-asp-net – AKMorris Jul 19 '17 at 01:44
  • I only run it in a localhost. – JJJ Jul 19 '17 at 02:32

2 Answers2

1

If you're referring to the "Scripts" directory in MVC app from the layout you can just reference as <script src="/Scripts/angular.js"></script>

  • I thought using ~ Virtual path is still okay – JJJ Jul 19 '17 at 03:09
  • It depends on where you're using it. If the page extension is .cshtml you can use the tilde. If it's .html or .js, you must avoid the tilde. In js, the tilde has a different meaning than "take me to the root". It is a Bitwise expression meaning NOT. That's why Angular doesn't resolve the tilde or any other bitwise character. – Die Hard Cubbie Jul 19 '17 at 03:14
  • Yeah I remember this in asp.net. – JJJ Jul 19 '17 at 05:03
0

Angular will not recognize the tilde in your script path. You'll need to resolve it traditionally.