Making simple program to share data as input in one to be updated in other through custom service only. I am writing bit of code I can, but need help to get it working for both controllers. Can someone help?
SNIPPET:
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js"></script>
</head>
<body ng-app="myApp">
<div class="div1" ng-controller="myCtrl1">
<input type="text" ng-model="name"> <span>{{name}}</span>
</div>
<div class="div2" ng-controller="myCtrl2">
<span>{{name}}</span>
</div>
<script>
//app declaration
var app = angular.module("myApp",[]);
//controllers declaration
app.controller('myCtrl1',function($scope, dummyService){
$scope.name = "Peter";
});
app.controller('myCtrl2',function($scope, dummyService){
$scope.name = "Roger";
});
//service declaration
app.service('dummyService',function(){
this.name = "Martin";
});
</script>
</body>
</html>
REQUIREMENT:
As soon as I start typing text in input box. It must start updating the same immediately in both the spans (viz in div1 and in div2).