This code is not working:
<td><img src="{{$rootScope.s3BucketUrl}}"/></td>
and this is where it's defined:
var appCtrl = app.controller('AppCtrl', function($scope, $resource, $location, $route, sharedProperties, $q, $rootScope){
defer = $q.defer();
//$rootScope.s3BucketUrl = 'http://lynd.s3.amazonaws.com/';//comment below one when live
$rootScope.s3BucketUrl = 'http://lynd-test.s3.amazonaws.com/';
//code omitted
});
AppCtrl is bound first on body tag.
Could anybody please suggest how do I print $rootScope variable?
scope(); $('#elementId'). scope(). $apply(); Another easy way to access a DOM element from the console (as jm mentioned) is to click on it in the 'elements' tab, and it automatically gets stored as $0 .
All applications have a $rootScope which is the scope created on the HTML element that contains the ng-app directive. The rootScope is available in the entire application. If a variable has the same name in both the current scope and in the rootScope, the application uses the one in the current scope.
The main difference is the availability of the property assigned with the object. A property assigned with $scope cannot be used outside the controller in which it is defined whereas a property assigned with $rootScope can be used anywhere.
Just use {{s3BucketUrl}}
and you would get the value.
Your current scope is a child scope of rootscope and hence you can always access the elements of rootscope.
This wiki is highly recommended
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With