Javascript AngularJS中的Access$route inside指令

Javascript AngularJS中的Access$route inside指令,javascript,angularjs,Javascript,Angularjs,如何访问$route内部指令功能 我主要想知道当前的模板URL,比如: app.directive("scrollable", function ($document) { return { restrict: 'A', link: function (scope, element, attrs) { $document.bind('scroll', function (evt) { console

如何访问
$route
内部指令功能

我主要想知道当前的
模板URL
,比如:

app.directive("scrollable", function ($document) {
    return {
        restrict: 'A',
        link: function (scope, element, attrs) {
            $document.bind('scroll', function (evt) {
                 console.log($route.current.templateUrl); // $route is undefined!
            });
        }
    };
});

另外,我是AngularJS的新手,不要太严格:)

我想你需要在指令中注入
$route

app.directive("scrollable", function ($document,$route) {

我认为您需要将
$route
注入指令

app.directive("scrollable", function ($document,$route) {

你试过把它传给指令吗?你用的是什么路由器?默认或ui路由器?您是否尝试过像
app.directive(“可滚动“,['$document','$route',function($document,$route){…])那样插入它为什么“-1”的家伙?太遗憾了…@MikeFeltman不,我没有试过。我是网络新手,你有没有试着把它传给指令?你用的是什么路由器?默认或ui路由器?您是否尝试过像
app.directive(“可滚动“,['$document','$route',function($document,$route){…])那样插入它为什么“-1”的家伙?太遗憾了…@MikeFeltman不,我没有试过。我是这个行业的新手,谢谢!它起作用了。我会在10分钟内接受你的回答:)谢谢!它起作用了。我会在10分钟内接受你的回答:)