AngularJs $watch on $location.search doesn't work when reloadOnSearch is false

前端 未结 6 683
一向
一向 2020-12-08 01:53

My routeProvider for route has reloadOnSearch set to false :

 $routeProvider
     .when(
        \"/film/list\",
         


        
6条回答
  •  失恋的感觉
    2020-12-08 02:39

    $watch(watchExpression, listener, [objectEquality]);

    watchExpression => should be either

    1. A string evaluated as expression or
    2. A function called with current scope as a parameter

    So here, You should pass your first parameter as a function.

    JavaScript Example =>

    $scope.$watch (
                    function () { return $scope.$location.search(); };
                    function (value) { console.log(value); } 
                  );
    

    Typescript example =>

    this.$scope.$watch (
                         () => { return this.$location.search(); },
                         (value: any) => { console.log(value); }
                       ) ;
    

    This did work for me.

提交回复
热议问题