Essential Angular for ASP.NET Core MVC by Adam Freeman
Author:Adam Freeman
Language: rus
Format: azw3, epub
Published: 2017-07-22T15:25:44+00:00
Chapter 7 ■ StruCturing an angular appliCation
The import statement provides access to the ProductDetailComponent class, which is added to the NgModule decorator’s declarations property. Now that the component can be used, edit the root component’s template to add the element that will apply the new component, as shown in Listing 7-12.
Listing 7-12. Adding an Element in the app.component.html File in the ClientApp Folder
<div class="container">
<div class="row">
<div class="col">
<category-filter></category-filter>
<product-table></product-table>
</div>
<div class="col">
<product-detail></product-detail>
</div>
</div>
</div>
The listing also adds some structure to the HTML document, using Bootstrap CSS classes to position the new component side-by-side with the existing ones.
Selecting a Product
The new component will display the details of a single product when it is selected, which means that the next step is to provide the user with the means to make that selection. First, add the elements shown in Listing 7-13 to the template for the product table.
Listing 7-13. New Elements in the productTable.component.html File in the ClientApp/app/structure Folder
<table class="table table-striped">
<tr><th>Name</th><th>Category</th><th>Price</th><th></th></tr>
<tr *ngFor="let product of products">
<td>{{product.name}}</td>
<td>{{product.category}}</td>
<td>{{product.price}}</td>
<td>
<button class="btn btn-primary btn-sm"
(click)="selectProduct(product.productId)">
Details
</button>
</td>
</tr>
</table>
The new elements add a column to the table containing a Details button for each row produced by the ngFor directive. The click event binding will invoke a method called selectProduct when the button is clicked, providing the ID value of the corresponding product. To define the method that the event binding invokes, add the code shown in Listing 7-14 to the product table component.
145
Download
Essential Angular for ASP.NET Core MVC by Adam Freeman.epub
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Deep Learning with Python by François Chollet(12571)
Hello! Python by Anthony Briggs(9916)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9796)
The Mikado Method by Ola Ellnestam Daniel Brolund(9779)
Dependency Injection in .NET by Mark Seemann(9340)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8300)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7763)
Grails in Action by Glen Smith Peter Ledbrook(7696)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(7087)
Microservices with Go by Alexander Shuiskov(6856)
Practical Design Patterns for Java Developers by Miroslav Wengner(6775)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6714)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6419)
Angular Projects - Third Edition by Aristeidis Bampakos(6123)
The Art of Crafting User Stories by The Art of Crafting User Stories(5649)
NetSuite for Consultants - Second Edition by Peter Ries(5583)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5389)
Kotlin in Action by Dmitry Jemerov(5066)
