Using $watch for two variables angularjs -
I have a pop up screen in which the user must choose between two drop down lists. After the selection completes, I return the selection to the service and save them in an object. App.service ('OriginalService', ['$ modal', function ($ modal) {var that = this; this.filtersMananger = {// my-ng- down-firstFilter lists: "", secondfilter: ""}; this.openDialog = function () {var modalInstance = $ modal.open ({TemplateUrl: 'ModalScreen.html', controller 'model controller, resolution: {filtersManagerObject: function () {that return.filtersMananger;}}}); modalInstance.result.then (function (filter Manager) {that.filtersMananger FirstFilter = filtersMananger.selectedFirstFilter; that.filtersMananger.secondFilter = filtersMananger.selectedSecondFilter;}, Function () {});};}]) ;;
Popup html:
& lt; Div class = "data-filter-container" & gt; & Lt; Div class = "data-filter" & gt; & Lt; Label for = "filter-data-drop-down" & gt; First filter & lt; / Label & gt; & Lt; Select Name = "FilterDataDowndowndown" ng-model = "FilterManager.Filter selected as" ng-option = "filter.Filter filter.DropDownItems for filter in." & Gt; & Lt; / Select & gt; & Lt; / Div & gt; & Lt; Div class = "data-filter collax-4-4" & gt; & Lt; Label = "filter-data-drop-down" & gt; SECOND FILTER & lt; / Label & gt; & Lt; Select Name = "Filter Data and Downdown" ng-model = "FilterManager. Selected" SecondFilter "ng-option =" Filter. For filter in filter.DropDownItems as filters. "& Gt; gt; & lt; / div & gt; However, this change is important and I have to call the controller who knows many other services to send information about this change To do this, I used a clock function in the controller: $ scope. $ Watch ('OriginalService.filtersMananger .firstFilter + OriginalService.filtersMananger.secondFilter ', function (newVal, OldVal) {if (newVal! == Puranaval) {any LOGIC dO}}); I am new Val and oldVal Comparison between Because the application is called when the application is uploaded, and we enter this function.
The problem is that in the new veal only the value of the second variable is the idea that the new veal Why is not the first variable in? $ watchCollection : use
Or if you are using angular 1.3 use $ watchGroup : $ scope $ WatchGroup ([ 'ServiceName. Object. The first variable', 'serviceName.Object.secondVariable'], function (Nuvalug, old value) {})
Comments
Post a Comment