Finding angular scope from javascript
(Created page with "Working with EXT_Components and integrating towards other services you may end up in situations where you get callbacks in client side javascript - and you will want to catch...")
 
No edit summary
Line 2: Line 2:


To get hold of your objects from such a callback (that are outside of the normal angular realm where you have some scope information at hand) you can go like this:
To get hold of your objects from such a callback (that are outside of the normal angular realm where you have some scope information at hand) you can go like this:
  var vmroot=angular.element('#some-element-within-html-that-is-your-view').controller().$scope.ViewModelRoot;
  var vmroot=angular.element('#viewmodelWrapper').controller().$scope.ViewModelRoot;
You now have the current local representation of your ViewModel in the vmroot variable and you can set properties like this:
You now have the current local representation of your ViewModel in the vmroot variable and you can set properties like this:
  vmroot.MyViewModelColumn=somevalueFromACallBack;
  vmroot.MyViewModelColumn=somevalueFromACallBack;
MDrivenTurnkey sees the property you change and handles signaling of server and binding of UI.
MDrivenTurnkey sees the property you change and handles signaling of server and binding of UI.
With some defensive error checking:
      function GetVMRoot(){
var ctrl=angular.element('#viewmodelWrapper').controller();
        if (ctrl !== undefined){
            return ctrl.$scope.ViewModelRoot;
        }
        return undefined;     
      }

Revision as of 14:15, 20 July 2020

Working with EXT_Components and integrating towards other services you may end up in situations where you get callbacks in client side javascript - and you will want to catch data from such a callback.

To get hold of your objects from such a callback (that are outside of the normal angular realm where you have some scope information at hand) you can go like this:

var vmroot=angular.element('#viewmodelWrapper').controller().$scope.ViewModelRoot;

You now have the current local representation of your ViewModel in the vmroot variable and you can set properties like this:

vmroot.MyViewModelColumn=somevalueFromACallBack;

MDrivenTurnkey sees the property you change and handles signaling of server and binding of UI.

With some defensive error checking:

      function GetVMRoot(){
	var ctrl=angular.element('#viewmodelWrapper').controller();
        if (ctrl !== undefined){
           return ctrl.$scope.ViewModelRoot;
        }					
        return undefined;      
      }
This page was edited 86 days ago on 02/10/2024. What links here