AngularJS : How do I switch views from a controller function?

前端 未结 8 603
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-30 16:49

I am trying to use the ng-click feature of AngularJS to switch views. How would I go about doing this with the code below?

index.html

 

        
8条回答
  •  时光取名叫无心
    2020-11-30 17:03

    This little function has served me well:

        //goto view:
        //useage -  $scope.gotoView("your/path/here", boolean_open_in_new_window)
        $scope.gotoView = function (st_view, is_newWindow)
        {
    
            console.log('going to view: ' + '#/' + st_view, $window.location);
            if (is_newWindow)
            {
                $window.open($window.location.origin + $window.location.pathname + '' + '#/' + st_view, '_blank');
            }
            else
            {
                $window.location.hash = '#/' + st_view;
            }
    
    
        };
    

    You dont need the full path, just the view you are switching to

提交回复
热议问题