Angular`location.path`中的location返回一个空字符串

问题描述 投票:0回答:1

我正在尝试更改导航菜单条目的颜色,以指示哪个是当前页面。但是location.path返回一个空字符串。我没有其他错误。

var mflfApp = angular.module("mflfApp", []);

mflfApp.controller('navController', ['$scope', '$location', function ($scope, $location) {
    $scope.isActive = function (destination) {
        // This function should indicate if the path provide in the destination correspond to the current 
        // locaiton.  This is then used to highlight an option in the navigation menu

        //  $location.path(); contains a blank string.  But does not throws an error.
        return destination === $location.path();
    }
}]);
angularjs location
1个回答
0
投票
return destination === $location.path();

如果您只是通过,则在destination变量中得到的字符串是:

return destination === $location.path(destination);

希望它对您有用。

© www.soinside.com 2019 - 2024. All rights reserved.