How to Display All Products Using AngularJS: A Comprehensive Guide
☰Fullscreen
Table of Content:
Display all Products
1. Display all Products
- There is a shopping application, Pick2get where users can view and buy products.
- Write a program to display a list of products with Product name, Brand name, Price, Discount value, and Product image as shown:
- Note: You need to add logic to the UI elements. Create a scope variable products that holds an array of products, where each product contains properties like:
name: Happy Cycle discount: 20% price: 2500 brand: Wheels image: cycle.jpg quantity: 2
Sample Code
index.htmlindex.js
{{pdt.discount}}Discount{{pdt.name}}Brand {{pdt.brand}}Price {{pdt.price}}
var app = angular.module('myApp', []); app.controller('myCtrl', function($scope) { var imgPath = "img/"; //add your $scope variable products here with below provided product details. });
Solution
index.jsvar app = angular.module('myApp', []); app.controller('myCtrl', function($scope) { var imgPath = "img/"; $scope.products = [ { name : "Happy Cycle", discount:"20%", price: "2500", brand : "Wheels", addedToCart:false, image : imgPath + "cycle.jpg", quantity:0 }, { name : "Kids Shoes", discount:"10%", price: "1460", brand : "Feel Good", addedToCart:false, image : imgPath + "shoes.jpg", quantity:0 }, { name : "Polo Baby Care Dress", discount:"20%", price: "2500", brand : "Super Hero", addedToCart:false, image : imgPath + "shirt.jpg", quantity:0 } ]; });