如何在控制器外获得当前的$ sce? [英] How to get current $sce outside controller?

查看:85
本文介绍了如何在控制器外获得当前的$ sce?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为获取控制器外的当前$ scope,我可以使用,

For getting current $scope outside controller I can use,

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

如何获得当前控制器$ sce?

How to get the current controllers $sce?

推荐答案

$ sce 是一项服务,因此您可以使用注射器访问它:

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'));

示例小提琴

这篇关于如何在控制器外获得当前的$ sce?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆