examples/angular/routing_from_code.html
<script src="angular.min.js"></script>
<script src="angular-route.min.js"></script>
<script src="routing_from_code.js"></script>

<div ng-app="DemoApp" ng-controller="DemoController">

<h1>{{title}}</h1>
<button ng-click="goto('/')">home</button>
<button ng-click="goto('first')">first</button>
 
<div ng-view></div>

</div>
examples/angular/routing_from_code.js
angular.module("DemoApp", ['ngRoute'])
.controller("DemoController", ['$scope', '$location', function($scope, $location) {
    $scope.title = "Routing from code";
    $scope.goto = function(page) {
        console.log(page);
        $location.path(page);
    };
}])
.config(['$routeProvider', function($routeProvider) {
    $routeProvider.
        when('/first', {
            template: '<h2>First Page</h2> from the template in the code',
        }).
        otherwise({
            redirectTo: '/'
        });
}]);