Click here to Skip to main content
15,891,762 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have
JavaScript
$scope.lstExtraSummaryModel

where on click of add button i am pusing data
i want whenver i chnage in
JavaScript
$scope.lstExtraSummaryModel

i showud get object

like

extrafield

lstExtraSummaryModel
JavaScript
$scope.lstExtraSummaryMod



JavaScript
$scope.extrafield = { 'lstExtraSummaryModel': $scope.lstExtraSummaryModel };


What I have tried:

I have
JavaScript
$scope.lstExtraSummaryModel

where on click of add button i am pusing data
i want whenver i chnage in
JavaScript
$scope.lstExtraSummaryModel

i showud get object

like

extrafield

lstExtraSummaryModel
JavaScript
$scope.lstExtraSummaryMod



JavaScript
$scope.extrafield = { 'lstExtraSummaryModel': $scope.lstExtraSummaryModel };
Posted
Updated 6-Aug-16 7:13am
Comments
Karthik_Mahalingam 6-Aug-16 12:21pm    
"whenver i chnage in" on what?
Member-515487 6-Aug-16 12:51pm    
Just like 2 way data binding i want it work with

$scope.extrafield.lstExtraSummaryModel=$scope.lstExtraSummaryMod


I m updating or inserting rcords in $scope.lstExtraSummaryMod

If i change or add contains

It should effects on
$scope.extrafield.lstExtraSummaryMod
Karthik_Mahalingam 6-Aug-16 12:53pm    
so whenever there is a change(add/remove) in $scope.lstExtraSummaryMod
it should get updated in $scope.extrafield.lstExtraSummaryMode ??? right?

is it a string array? lstExtraSummaryMod
Member-515487 6-Aug-16 13:09pm    
No its not getting updated its shows always 0 count
Member-515487 6-Aug-16 13:11pm    
No its not getting updated

use Angular Watch[^]
$watch in AngularJS[^]

JavaScript
$scope.$watch('lstExtraSummaryMod', function (newValue, oldValue, $scope) {
             $scope.extrafield.lstExtraSummaryModel =  $scope.lstExtraSummaryMod
         });
 
Share this answer
 
Comments
Member-515487 6-Aug-16 13:15pm    
Thanks.....
Karthik_Mahalingam 6-Aug-16 13:23pm    
welcome
Member-515487 6-Aug-16 13:22pm    
My code i want to improve with typescript
Can u please guide how i can do
Karthik_Mahalingam 6-Aug-16 13:26pm    
TypeScript?, Sorry i haven't worked on it.
Member-515487 7-Aug-16 7:58am    
$scope.$watch('lstExtraSummaryMode', function (newValue, oldValue, $scope) {
$scope.extrafield.lstExtraSummaryModel = $scope.lstExtraSummaryMode
});
my both objects are same only
$scope.extrafield.lstExtraSummaryModel = $scope.lstExtraSummaryMode
so why this code is not working directly
(function (app) {
app.controller('ReportCtrl', reportcntr);
function reportcntr($scope)
{
$scope.safeApply = function (fn) {
var phase = this.$root.$$phase;
if (phase == '$apply' || phase == '$digest') {
if (fn && (typeof (fn) === 'function')) {
fn();
}
} else {
this.$apply(fn);
}
};

//$scope.extrafield.push({'lstExtraSummaryModel': $scope.lstExtraSummaryModel });
$scope.lstFieldsList = [];
$scope.lstExtraSummaryModel = [];
$scope.extrafield=[];

$scope.lstFormat = [];
$scope.lstSummaryType = [];
$scope.FieldName = '';
$scope.SummaryID = '';
$scope.SummaryType = '';
$scope.Caption = '';
$scope.FormatID = '';
$scope.FormatType = '';
$scope.FormatString = '';
$scope.ErrorMsg = '';
$scope.isUpdate = false;
$scope.removeRow = function (deleteindex) {
var index = -1;
if (index === deleteindex) {
$scope.ErrorMsg = 'Something gone wrong';
}
$scope.lstExtraSummaryModel.splice(deleteindex, 1);
$scope.extrafield.lstExtraSummaryModel = $scope.lstExtraSummaryModel;
if (!$scope.isUpdate) {
pivotGrid.PerformCallback();
}
};
$scope.refresh = function () {
pivotGrid.PerformCallback();
};
$scope.addRow = function () {
if ($('#frmCustomSummary').valid()) {
var data = _.where($scope.lstExtraSummaryModel, { 'Caption': $scope.Caption })
if (data.length == 0) {
data = _.where($scope.lstFieldsList, { 'FieldName': $scope.Caption })
if (data.length == 0) {
$scope.lstExtraSummaryModel.push({ 'FieldName': $scope.FieldName, 'SummaryID': $scope.SummaryID.Value, 'SummaryType': $scope.SummaryID.Text, 'Caption': $scope.Caption, 'FormatID': $scope.FormatID.Value, 'FormatType': $scope.FormatID.Text, 'FormatString': $scope.FormatID.Attribute });
$scope.extrafield.lstExtraSummaryModel = $scope.lstExtraSummaryModel;
$scope.FieldName = '';
$scope.SummaryID = '';
$scope.SummaryType = '';
$scope.Caption = '';
$scope.FormatID = '';
$scope.ErrorMsg = '';
if (!$scope.isUpdate) {
pivotGrid.PerformCallback();
}

}
else {
$scope.ErrorMsg = 'Field Already Exist.';
}
}
else {
$scope.ErrorMsg = 'Caption Already Exist.';
}
}
};

$scope.clear = function () {
$scope.FieldName = '';
$scope.SummaryID = '';
$scope.SummaryType = '';
$scope.Caption = '';
$scope.FormatID = '';
$scope.ErrorMsg = '';
};
}
})(angular.module('pfmstool'))
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900