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

前端 未结 8 616
爱一瞬间的悲伤
爱一瞬间的悲伤 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条回答
  •  萌比男神i
    2020-11-30 16:54

    In order to switch between different views, you could directly change the window.location (using the $location service!) in index.html file

    edit
    preview

    Controller.js

    function Cntrl ($scope,$location) {
            $scope.changeView = function(view){
                $location.path(view); // path not hash
            }
        }
    

    and configure the router to switch to different partials based on the location ( as shown here https://github.com/angular/angular-seed/blob/master/app/app.js ). This would have the benefit of history as well as using ng-view.

    Alternatively, you use ng-include with different partials and then use a ng-switch as shown in here ( https://github.com/ganarajpr/Angular-UI-Components/blob/master/index.html )

提交回复
热议问题