logo
down
shadow

Can not figure out how to store $rootScope in angular.bootstrap


Can not figure out how to store $rootScope in angular.bootstrap

By : user2956263
Date : November 22 2020, 10:54 AM
To fix this issue $scope (and $rootScope for that matter) is suppose to act as the glue between your controllers and views. I wouldn't use it to store application type information such as user, identity or security. For that I'd use the constant method or a factory (if you need to encapsulate more logic).
Example using constant:
code :
var app = angular.module('myApp',[]);

app.controller('MainCtrl', ['$scope','user',
function ($scope, user) {
    $scope.user = user;
}]);

angular.element(document).ready(function () {
    var user = {};
    user.codeCampType = "svcc";
    app.constant('user', user);
    angular.bootstrap(document, ['myApp']);    
});


Share : facebook icon twitter icon
How do I use $rootScope in Angular to store variables?

How do I use $rootScope in Angular to store variables?


By : Sanithra
Date : March 29 2020, 07:55 AM
around this issue Variables set at the root-scope are available to the controller scope via prototypical inheritance.
Here is a modified version of @Nitish's demo that shows the relationship a bit clearer: http://jsfiddle.net/TmPk5/6/
code :
angular.module('myApp', [])
.run(function($rootScope) {
    $rootScope.test = new Date();
})
.controller('myCtrl', function($scope, $rootScope) {
  $scope.change = function() {
        $scope.test = new Date();
    };

    $scope.getOrig = function() {
        return $rootScope.test;
    };
})
.controller('myCtrl2', function($scope, $rootScope) {
    $scope.change = function() {
        $scope.test = new Date();
    };

    $scope.changeRs = function() {
        $rootScope.test = new Date();
    };

    $scope.getOrig = function() {
        return $rootScope.test;
    };
});
Which is the best way to store several external json file in $rootScope in Angular 1.5?

Which is the best way to store several external json file in $rootScope in Angular 1.5?


By : Vinny
Date : March 29 2020, 07:55 AM
it helps some times Don't use $rootScope, for application configuration is recommended use a specific module with the configuration info and register each configuration block as `constant'.
In your case the server side configuration made a bit more complex. See Asynchronously Bootstrapping AngularJS Applications with Server-Side Data
code :
(function() {
    var appConfig=angular.module("app.config");
    var initInjector = angular.injector(["ng"]);
    var $http = initInjector.get("$http");

    $http.get('config/config.json').success(function(configResponse) {
       appConfig.constant("config", configResponse);
    });
   $http.get('preferences/preferences.json').success(function(prefsResponse {
       appConfig.constant("preferences", preferencesResponse);
    });


})());
angular.module("app",["app.config"])
Angular: using $rootScope.$on vs $scope.$on to catch a $rootScope.$broadcast in a component – what is better in terms of

Angular: using $rootScope.$on vs $scope.$on to catch a $rootScope.$broadcast in a component – what is better in terms of


By : Jes
Date : March 29 2020, 07:55 AM
I hope this helps . I don't really understand why people here seem to be so obsessed with performance. You should only worry about performance when you have a performance problem. Otherwise, it's premature optimization, which is the root of all evil.
In that case, the evil might be memory leaks, and much performance problems.
How to set value on $rootScope after angular.bootstrap()

How to set value on $rootScope after angular.bootstrap()


By : Tomo Yanagi
Date : March 29 2020, 07:55 AM
it helps some times The bootstrap function returns the $injector, so you could do something like this:
Is it possible to implement a Redux-like architecture in Angular 1 using $rootScope as the store?

Is it possible to implement a Redux-like architecture in Angular 1 using $rootScope as the store?


By : Nakeel
Date : March 29 2020, 07:55 AM
I hope this helps . Of course, you can do your thing using only $rootScope. But is has a lot of other purposes that will interfere with your state.
Let's see:
Related Posts Related Posts :
  • what can or cannot be done with a controller created in a module Vs controller created globally?
  • Angularjs - add ng-* attributes using directives
  • Why are my Angular, absolute path, URL's not compiling properly with Closure Compiler?
  • AngularJS routing not working properly in PhoneGap
  • AngularJS: Create new scope variable name using a variable value
  • Directive scope update does not update controller scope (AngularJs)
  • Unit-test a angular controller function in a directive
  • jQuery Sparkline in a cell in ng-grid using CellTemplate and Directive
  • AngularJS determine filter in controller
  • How to deploy an app using ionic framework to Amazon? (elastic beanstalk prefered)
  • Conditional injection of a service in AngularJS
  • Filtering on object properties not working
  • Open $modal from the service and pass variables to the controller
  • ngClick evaluated against scope instead of isolateScope
  • onEnter and onExit are not called when state is left/activated in angularjs ui router
  • Shared client & server modules with angularjs and pongular
  • Getting the angular app to run when using protractor
  • Angularjs: create a link for download different types of file
  • AngularJS: On Change of Parent DropDown Option Also Changes the Dependant Drop Down Options Associated with Other Parent
  • Angular HTML5 mode, Wordpress, Rewrites, Apache and You
  • Using angular js form validations in <form:input> tag
  • AngularJS call common functions in a directive template
  • AngularJS Promise resolved incorrectly
  • properly clearing whole AngularJS ui-grid chart
  • animate.css animation within angularjs 1.3 using ngAnimate gives different animations in Firefox
  • Auth0 IE Issue: Unable to get property 'frames' of undefined or null reference
  • Am I misusing directives with too much logic?
  • Use an Angular JS value as a parameter of TWIG "path" function in Symfony 2
  • multiple function on ng-click angularjs
  • Converting $.ajax call to $http call in angular 404 error
  • Angularjs templateUrl file location not found
  • How to execute the function after change page in angularjs?
  • Pass variable to AngularJS directive without isolated scope
  • OAuth, Custom Login, or Both
  • Angular Directive: Isolate Scope & Transclude is true, but HTML in the directive needs to continue to bind to parent
  • Compare objects in angularjs
  • Combine "Checkbox" & "Avatar" in an Ionic Framework List
  • Issue with the Angular UI router when inheriting from a parent state
  • Is there a way to initialize an Angular Service without DI into controller
  • Why is a parent controller's $scope not accessible from a (child) directive?
  • How to get back button in Ion-tabs page
  • AngularJS bind class attribute to model
  • How can I get AngularJS ui-router to respond correctly to a browser page refresh?
  • Angular validation does not work
  • Breez Create Complex Entities
  • Drag and drop using protractor in dthmlx component
  • In Angular JS, what is the default 'cache' value that is used when sending request with $http service?
  • How to change placeholder for single textbox in angular?
  • $ is not defined - jquery angular mixing
  • CORS issue angularjs and spring security
  • Angularjs cannot select last item in dropdown the first time
  • Angularjs - $watch issue
  • On change radio button to no the span should hide in angular
  • Creating a wordcloud generator in Angularjs
  • Angular UI Bootstrap collapse - whats wrong?
  • AngularJS after redirect from app to app, the default page is not loading
  • Why does my scope update my factory and my factory update my scope when it should not?
  • AngularJS testing $httpBackend.whenGET().respond() not working with number as parameter
  • Setting up Login in Angular App
  • Retrieve value that is stored in db and display in select box using angularjs and laravel
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org