"
ASP.NET (snapshot 2017) Microsoft documentation and samples

Breeze/Angular template

by Mads Kristensen

The Breeze/Angular MVC Template was written by Ward Bell

Download the Breeze/Angular MVC Template

AngularJS is an open source library from Google for building Single Page Applications (SPAs). It offers data binding, dependency injection, and screen management. Combine it with BreezeJS, another open source library for data modeling and data management, and you have the essential ingredients for a great HTML/JavaScript client app.

The Breeze/Angular SPA template is a variation on the KnockoutJS SPA template included in the ASP.NET and Web Tools 2012.2 Update. If you’ve got Visual Studio, you’ll have an example SPA up and running in less than 60 seconds.

Outwardly, the application looks the very similar to the KnockoutJS SPA template. But it’s quite different under the hood. The KnockoutJS template uses Knockout for data binding and raw AJAX for data access. The Breeze/Angular template uses Angular for data binding and Breeze for data access. These libaries enable additional capabilities, including page navigation and history.

Here is the application’s About page:

This page displays a running log of events during the current user session, including:

There’s more to explore in this template, including:

Let’s get started.

Create a Breeze/Angular Template Project

Download and install the template by clicking the Download button above. The template is packaged as a Visual Studio Extension (VSIX) file. You might need to restart Visual Studio.

In the Templates pane, select Installed Templates and expand the Visual C# node. Under Visual C#, select Web. In the list of project templates, select ASP.NET MVC 4 Web Application. Name the project and click OK.

In the New Project wizard, select Breeze Angular SPA.

Press Ctrl-F5 to build and run the application without debugging, or press F5 to run with debugging.

When the application first runs, it displays a login screen. Click the “Sign up” link and a new page glides into view, where you can enter a username and password. (The login and registration pages are built using ASP.NET MVC.) When you submit the registration form, the server generates a TodoList with two items for your account. Then it presents them to you on a yellow note.

Now you are in the land of SPA. Everything you see and experience while manipulating Todos is rendered and managed on the client with the help of Knockout and Breeze. Explore the app as a user … but with a developer’s eye. Use the developer tools in your browser to capture the network traffic. (In Internet Explorer: Press F12, select the Network tab, and click Start capturing.) Now try the following:

The validation logic is performed client-side by Breeze. Validation attributes on the server model classes are propagated to the client and executed automatically before the client contacts the server.

Review the network traffic. Notice that there were no calls to the server when Breeze detected an error. Each valid change resulted in a POST request to “/api/Todo/SaveChanges”. Breeze bundles the changes and sends them together as a single request to the Web API controller’s SaveChanges method. That’s different from KockoutJS SPA template, which makes PUT, POST, and DELETE requests for each item individually.

Also, notice there is no network traffic when you switch between the TodoList and About pages. That’s because the query has been constrained to the local Breeze cache.

Peek inside

This application has a client side and a server side. The client-side stack consists of a little HTML and a combination of application JavaScript modules (in the “app” folder) plus third-party JavaScript libraries (in the “Scripts” folder).

The UI architecture separates the HTML widgets of the views from the supporting presentation code in the controllers. The Angular data-binding system coordinates views and controllers so that each can do its job without intimate knowledge of the other.

The controller asks the data context to acquire and save the model entities. The data context delegates most of the work to Breeze, which constructs self-tracking model objects from JSON query results.

The server-side stack consists of some developer code and three principle .NET libraries: Web API, Entity Framework, and Breeze.NET:

The basic architecture is the same as the KockoutJS SPA template. However, the implementation is much simpler: The DTOs were deleted, and most of the Entity Framework details have been delegated to Breeze.NET.

Next Steps

We suggest that you explore the code, guided by the extensive discussion of both the client and the server stacks on the Breeze website.

You might try playing with Breeze client-side query; add some filters and sorts. You might add more model properties and more entities to get a better feel for end-to-end SPA development. When you are confident of the design, you can tear out the Todo features and replace them with your own.

Happy coding!



Comments ( )
Link to this page: //www.vb-net.com/AspNet-DocAndSamples-2017/aspnet/single-page-application/overview/templates/breezeangular-template.htm
< THANKS ME>