Skip to content Skip to sidebar Skip to footer

How To Set A Property Of Scope In The Controller When It Is Available In Angular?

I have a global JS object called instance_ It has a property called current_ Which later gets a property called dataset_ so basicaly instance_.current_.dataset_ I use this dataset_

Solution 1:

This may be one solution. Add a factory to your app, like this:

myApp = angular.module('myApp', []);
myApp.factory('myGlobalDataSet', function(){
    return instance_.current_.dataset_;
});

Then pass the factory's value into your controller:

functionmyController($scope, myGlobalDataSet) {
  $scope.myGlobalDataSet = myGlobalDataSet;
}

Then within your views you should be able to access the myGlobalDataSet variable. If you tie it with an ng-model then it should bind your global value with the details of the view.

Post a Comment for "How To Set A Property Of Scope In The Controller When It Is Available In Angular?"