Hi Pablo,
There is quiet a bot of code but yes they are in nested controllers, here's
some code. Once the update function in controller 2 is done the listlength
variable updates accordingly but the updated value doesn't carry over to
the third controller, why is that?
app.controller("controller1", function($scope){
$scope.list = []; //this gets populated with data from a database
$scope.listLength = $scope.list.length;
});
app.controller("controller2", function($scope){
$scope.$watch('listLength', function(newVal, oldVal){
if($scope.listLength !== newVal) $scope.listLength = newVal;
});
}); //I have watch functions within the controllers like so
app.controller("controller3", function($scope){
$scope.$watch('listLength', function(newVal, oldVal){
if($scope.listLength !== newVal) $scope.listLength = newVal;
});
});
On Sunday, March 27, 2016 at 7:29:09 PM UTC+2, Pablo Madalena Targa wrote:
>
> Can you set a simple env of the three controllers and the interaction
> between them, in pastebin, fiddlejs or codepen?
>
> Are they nested controllers, how are you sharing the $scope?
>
> On Sun, Mar 27, 2016 at 5:59 PM, <[email protected] <javascript:>>
> wrote:
>
>> Hi Pablo,
>>
>> Yes I have tried that I have put watches in three of my controllers, the
>> add, edit and delete but on the add it still doesn't update my array. Does
>> it have to be placed in a particular place to work?
>>
>> On Sunday, March 27, 2016 at 4:50:04 PM UTC+2, Pablo Madalena Targa wrote:
>>>
>>> Hi friend,
>>>
>>> have you tried this?
>>>
>>> $scope.$watch('list.length', function(newValue, oldValue){...});
>>>
>>> On Sun, Mar 27, 2016 at 3:15 PM, <[email protected]> wrote:
>>>
>>>> I have an empty array defined as $scope.list = [] I then select items
>>>> from the database and push them into the array as an object like so {
>>>> name:"john", surname:"doe, age:35 } I have stored the length of the list
>>>> in
>>>> an variable however upon deleting items or adding items to the array
>>>> doesn't update it's length. What am I doing wrong? Here is my code
>>>>
>>>> $scope.list = [];
>>>> var scopeListLength = $scope.list.length;
>>>> $scope.$watch(scopeListLength, function(newVal, oldVal){
>>>> console.log(newVal);
>>>> console.log(oldVal);
>>>> if(newVal !== oldVal) scopeListLength = newVal;
>>>> console.log("scopeListLength = " + scopeListLength);
>>>> });
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "AngularJS" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> To post to this group, send email to [email protected].
>>>> Visit this group at https://groups.google.com/group/angular.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>> --
>> You received this message because you are subscribed to the Google Groups
>> "AngularJS" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected]
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/angular.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.