service - Update when something changes in the website Angularjs -


I have a question, I have two different controllers, such as:

  & Lt; Div ng-app = 'demoApp' & gt; & Lt; Div ng-controller = 'FirstCtrl' & gt; {{Date | Date: 'yyyy-MM-dd hh: mm: ss'}} & lt; / Div & gt; & Lt; Div ng-controller = 'secCtrl' & gt; & Lt; Button type = "submit" ng-click = "update ()" & gt; Add & lt; / Button & gt; & Lt; / Div & gt; & Lt; / Div & gt;  

When I click on another controller's button, I want to update the date in the first controller.

This is jsfiddle:

If you type $ scope.date = New date () , then you do not track it in your reference property property second controller. You have to cache the context of your update service in the $ scope.model property to correct this problem.

  angular.module ('demoep', []). Controller ('firstcurrent', function ($ scope, update) {$ scope.model = UpDate;}) Controller ('SecCtrl', Function ($ Scope, Update) {$ scope.model = UpDate; $ scope.update = function () {$ Scope Model.date = New Date ();};}) Service ('update', function) (this.date = new date ();});  


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -