How to get current $sce outside controller?

For getting current $scope outside controller I can use,

 var $scope = angular.element('[ng-controller=ProductCtrl]').scope();

How to get the current controllers $sce?

Answers:

Answer

The $sce is a service so you can access it using the injector:

var elem = angular.element('[ng-controller=ProductCtrl]');
console.log("$scope: ",elem.scope());
console.log("$sce: ",elem.injector().get('$sce'));

example fiddle

Answer

Better use a service to pass data between controllers or other services. Services act like a Singleton.

Here is an example

Answer

For now my fix is,

window.trustAsHtml = $sce.trustAsHtml

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.