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

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?


 <div ng-controller="Cntrl">
        <div ng-click="someFunction()">
            click me


  function Cntrl ($scope) {
        $scope.someFunction = function(){
            //code to change view?

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

<div ng-controller="Cntrl">
        <div ng-click="changeView('edit')">
        <div ng-click="changeView('preview')">


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 ). 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 ( )

The provided answer is absolutely correct, but I wanted to expand for any future visitors who may want to do it a bit more dynamically -

In the view -

<div ng-repeat="person in persons">
    <div ng-click="changeView(person)">
        Go to edit

In the controller -

$scope.changeView = function(person){
    var earl = '/editperson/' +;

Same basic concept as the accepted answer, just adding some dynamic content to it to improve a bit. If the accepted answer wants to add this I will delete my answer.

I've got an example working.

Here's how I have my doc looks:

    <link rel="stylesheet" href="css/main.css">
    <script src="//"></script>
    <script src=""></script>
    <script src=""></script>
    <script src="js/app.js"></script>
    <script src="controllers/ctrls.js"></script>
<body ng-app="app">
    <div id="contnr">

Here's what my partial looks like:

<div id="welcome" ng-controller="Index">
    <b>Welcome! Please Login!</b>
    <form ng-submit="auth()">
        <input class="input login username" type="text" placeholder="username" /><br>
        <input class="input login password" type="password" placeholder="password" /><br>
        <input class="input login submit" type="submit" placeholder="login!" />

Here's what my Ctrl looks like:

app.controller('Index', function($scope, $routeParams, $location){
    $scope.auth = function(){

app is my module:

var app = angular.module('app', ['ngResource']).config(function($routeProvider)...

Hope this is helpful!

The method used for all previous answers to this question suggest changing the url which is not necessary, and I think readers should be aware of an alternative solution. I use ui-router and $stateProvider to associate a state value with a templateUrl which points to the html file for your view. Then it is just a matter of injecting the $state into your controller and calling $state.go('state-value') to update your view.

Difference between angular-route and angular-ui-router

Without doing a full revamp of the default routing (#/ViewName) environment, I was able to do a slight modification of Cody's tip and got it working great.

the controller

.controller('GeneralCtrl', ['$route', '$routeParams', '$location',
        function($route, $routeParams, $location) {
            this.goToView = function(viewName){
                $location.url('/' + viewName);

the view

<li ng-click="general.goToView('Home')">HOME</li>

What brought me to this solution was when I was attempting to integrate a Kendo Mobile UI widget into an angular environment I was losing the context of my controller and the behavior of the regular anchor tag was also being hijacked. I re-established my context from within the Kendo widget and needed to use a method to navigate...this worked.

Thanks for the previous posts!