我将此 Controller 附加到 div:
.controller('ShowInverterConnectController', ['$scope', '$location', function($scope, $location) {
....
}])
我想使用它的 $location 参数。
我目前正在这样做:
angular.element('.ng-scope').scope().$apply(function() {
console.log('test:', angular.element('.ng-scope').scope().$location);
});
但是 $location 未定义,有什么办法可以使用 $location 吗?
谢谢
最佳答案
不确定您想在应用程序之外使用 Angular 服务做什么,但我认为您有充分的理由,因为在许多情况下这将被认为是不好的做法。反正。
$location
不是作用域的属性,因此您无法像您正在尝试的那样获得它。但是您可以使用 $injector
用于检索其他服务的服务,例如 $location
:
angular.element('.ng-scope').scope().$apply(function() {
console.log('test:', angular.element('.ng-scope').injector().get('$location'));
});
关于javascript - 从 jquery 调用 Controller 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31121789/