3

i m facing an odd issue, i have defined an object (globally for application) that holds array object looks like

var _global = {
        document: {}, // represent selected item
    };

and in my service i have something like this

_global.document.signers =[{name:'test',email:'[email protected]'}];

its working fine. now if i push element like

_global.document.signers.push({name:'test',email:'[email protected]'});

and in controller i use

var signers = _global.document.signers;

it works fine . view gets updated with new values

but in case if i do something

_global.document.signers = [{name:'newTest',email:'[email protected]'}];

global object gets updated but view doesn't render new values and if i change it to push view starts rendering new values

can some one guide me wat i m doing wrong . any help will be appreciated

Updated

Thanks @shani for help i have solved it using

var draft = globalService.getGlobal(); //global service for maintaining global objects
$scope.draft = draft;

and in view

 <ul class="list-unstyled font-11px" >
       <li ng-repeat="(signerIndex, signer) in draft.document.signers">
    </li></ul>
3
  • First , do not use global variables, use a service! Second it is probably a $watch issue so post your controller / view code Commented Feb 18, 2014 at 12:26
  • i have defined a global service for mainlining global variables .secondly i didnt used watch wat i have done in my controller is $scope.signers = _global.document.signers Commented Feb 18, 2014 at 12:31
  • Again show your code ( controller / view ) Commented Feb 18, 2014 at 12:32

1 Answer 1

2

Assign your global object to your controller scope, as services are singletons if there is change in service objects, your controller will automatically react to it.

Sign up to request clarification or add additional context in comments.

3 Comments

can u explain bit more :) basically i didn't get wat u mean by assign your global object to ur controller
What i do in controller basically is var object = globalservice.globalobject(); $scope.signers = object;
thanku its working fine my mistake was, i was directly assigning to signers rather to object Thanks again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.