javascript - value is changing before save- angular js -


I have created an application in angular JS, in which I am getting JSN from a factory, on which it has two controllers < The code taken in Ctrl1 and Ctrl 2 is working fine but in the structure I have canceled and saved the button, in which I cancels when I have previously saved changes It has to be done again and when I click it, it should update json.

html

  & lt; Div ng-app = "app" & gt; & Lt; Div ng-controller = "ctrl1" & gt; & Lt; Form & gt; & Lt; Br> & Lt; / Br & gt; {{}} User & lt; / Form & gt; & Lt; / Div & gt; & Lt; Div ng-controller = "ctrl2" & gt; & Lt; Input type = "text" ng-model = "user.name" /> & Lt; Br> & Lt; Input type = "button" ng-click = "save ()" value = "save" /> & Lt; Input type = "button" ng-click = "cancel ()" value = "cancel" /> & Lt; / Div & gt; & Lt; / Div & gt;  

script

  var app = angular Module ("app", []); App.factory ('InitApp', function () {return {name: 'manu', age: 15};}); App.controller ('Ctrl1', function ($ area, InitApp) {$ scope.user = InitApp;}); App.controller ('Ctrl2', function ($ area, InitApp) {$ scope.user = InitApp; $ scope.save = function () {} $ scope.cancel = function () {}});  

I'm guessing that changing value is not desired before saving what you do They want to copy the object to their controller and manipulate the copy.

  app.controller ('ctrl1', function ($ radius, intetch) {$ scope.user = angle (InitApp);});  

This disconnects the controller object from the service object, leaving you with a source of truth in the service. Cancellation can be rebounded on the service object.

In addition to this, you are returning properties in your Bela and you are manipulating the service in your controller. You need to return something instead, so that you can not service the service directly and breaking it down.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -