有什麼辦法如何訪問$route
裏面的指令函數?
我基本上是想知道當前templateUrl
,說:
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新手,別那麼嚴謹:)
你有沒有試過把它傳遞給指令? –
你使用什麼路由器?默認或ui路由器? –
你有沒有嘗試注入它像'app.directive(「scrollable」,['$ document','$ route',function($ document,$ route){...}]);' –