Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Trying to Use AngularJS with ASP.NET Core

$
0
0

I'm trying to use Angular for the first time to build a Single Page Application (SPA) in ASP.NET Core 1.0.

With ASP.NET MVC applications I'm used to having a Layout Page (aka Master Page) and a number of View pages (ex. Index.cshtml).  However, when using Angular, there seems to be some sort of disconnect such that the Angular loaded in the Layout Page is not available in the View.

For example, in my _Layout.cshmtl page there is this section:

<environment names="Development"><script src="~/lib/jquery/dist/jquery.js"></script><script src="~/lib/bootstrap/dist/js/bootstrap.js"></script><script src="~/js/site.js" asp-append-version="true"></script><script src="~/lib/angular/angular.js"></script></environment>

Here is a very simple Index.cshtml:

<html><body ng-app="app"><h1>Content Push Editor</h1><div>

        {{2+2}}</div><script type="text/javascript">
        angular.module('app', []);</script></body></html>

But with this combo I get this error in Firebug:

ReferenceError: angular is not defined
http://localhost:52848/
Line 27

I'm thinking this might be a sequencing thing, with the Body being rendered before the Scripts Section but thought I'd ask the experts.

Robert


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>