Here is my plunker link: https://plnkr.co/edit/oo05d6H6AxuJGXBAUQvr?p=preview
I'm trying to develop an application where I have elements inside an array. When I click on each element details will be displayed, but I'm not able to display image,
How can I add an image attribute inside an array and again display it using html page?
script.js:
var app = angular.module("myApp", ["ngRoute"]);
app.controller('mobileController', function($scope) {
$scope.items = [{
name: 'Iphone',price:70000,rating:'*****',image: 'how to add image here'
}, {
name: 'Oneplus',price:60000,rating:'****',image: 'how to add image here'
}, {
name: 'Samsung',price:50000,rating:'***',image: 'how to add image here'
}, {
name: 'Sony',price:40000,rating:'***',image: 'how to add image here'
}, {
name: 'Moto',price:20000,rating:'****',image: 'how to add image here'
}];
});
app.config(function($routeProvider) {
$routeProvider
.when('/item/:itemName/:itemPrice/:itemRating/:itemImage', {
templateUrl: 'details.html',
controller: 'ItemCtrl'
});
});
app.controller('ItemCtrl', ['$scope', '$routeParams',
function($scope, $routeParams) {
$scope.itemName = $routeParams.itemName;
$scope.itemPrice = $routeParams.itemPrice;
$scope.itemRating = $routeParams.itemRating;
$scope.itemImage = $routeParams.itemImage;
}
]);
index.html
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.js"></script>
<script src="script.js"></script>
<body ng-app="myApp" ng-controller="mobileController">
<h2> Welcome to Mobile Store</h2>
<p>Search:<input type="text" ng-model="test"></p>
<ul>
<li ng-repeat="item in items|filter:test">
<a href="#/item/{{item.name}}/{{item.price}}/{{item.rating}}/{{item.image}}">{{ item.name }}</a>
</li>
</ul>
<div ng-view></div>
</body>
</html>
details.html
<p>ItemName: {{itemName}}</p>
<p> ItemPrice: {{itemPrice}}</p>
<p>ItemRating:{{itemRating}}</p>
<p>{{itemImage}}</p>
ng-srchow to add image herewith/pah/to/image.pngthen you can use<img src="{{itemImage}}">