How to get current $sce outside controller?

后端 未结 3 1432
庸人自扰
庸人自扰 2021-01-16 05:49

For getting current $scope outside controller I can use,

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

How to get

相关标签:
3条回答
  • 2021-01-16 06:09

    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

    0 讨论(0)
  • 2021-01-16 06:16

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

    Here is an example

    0 讨论(0)
  • 2021-01-16 06:26

    For now my fix is,

    window.trustAsHtml = $sce.trustAsHtml
    
    0 讨论(0)
提交回复
热议问题