用routeParams观看路线不起作用

时间:2018-06-28 09:04:21

标签: angularjs angular-ui-router

我有一个$ watch设置,它监视UI路由器路径并在location.path等于特定路由的情况下触发某些事件。这适用于其中没有参数的所有路由。有谁知道解决方法?

这是代码

    $scope.$watch(function() {
        return $location.path();
      }, function(){

            if(
                $location.path() == '/dashboard' ||
                $location.path() == '/mySettings' ||
                $location.path() == '/myAccount' ||
                $location.path() == '/new_company' ||
                $location.path() == '/company/view/:id' ||
                $location.path() == '/companies/view/all' ||
                $location.path() == '/agreement/new' ||
                $location.path() == '/agreement/:id/map' ||
                $location.path() == '/invitation/new' ||
                $location.path() == '/inbox'
              ) {

                  sessionWatcher();

              } else {

                var myEl = angular.element( document.querySelector( '#wrapper' ) );
                myEl.addClass('authPage');

                var myEl = angular.element( document.querySelector( '#page-content-wrapper' ) );
                myEl.addClass('fullScreen');

                checkSessionFalse();

              }

      });

1 个答案:

答案 0 :(得分:0)

确定了。

如果其他人遇到此问题,我建议使用与jquery contains方法相似的indexOff方法。

$location.path().indexOf('thevaluetocheck') > -1

在以下链接上找到更多信息

https://docs.angularjs.org/api/ng/service/ $ location