I have a view that I want the view the to get newly updated price everytime I click the change price button. I used a service that stores the newPrice that gets his value from the priceModel. so far I can't get the price to updated in the DOM when i press the button.
this is my html
<body ng-app="my-app">
<div ng-controller="my-controller">
<h1>Products</h1>
<input type="text" ng-model="priceModel" />
<br/>
<button type="button" ng-click="changePrice()">Change Price</button>
</div>
<div ng-controller='priceController'>
Price {{price}}
</div>
</body>
this is my javascript
var app = angular.module('my-app', [])
.controller("my-controller", function($scope, Products) {
var newPrice = '';
$scope.changePrice = function(){
newPrice = $scope.priceModel;
Products.price(newPrice);
}
})
.controller('priceController', function(Products, $scope){
$scope.price = Products.price();
})
.service('Products', function(){
this.price = function(newPrice){
return newPrice;
};
})