0

I am new to angularJS and trying to create a simple application. I have come to an issue when i click on a button, on say, the index.html page, i want to be forwarded to the .search.html page.

Here is my button on index.html:

<body ng-controller="mainController">
    <button ng-click="GoToNext2('/search')">Search</button>
</body>

Here is my angular code:

// create the module and name it scotchApp
var scotchApp = angular.module('scotchApp', ['ngRoute']);

// configure our routes
scotchApp.config(function($routeProvider) {
$routeProvider

    // route for the home page
    .when('/', {
        templateUrl : 'home.html',
        controller  : 'mainController'
    })

    .when('/search', {
        templateUrl : 'Search.html',
        controller  : 'searchController'
    });
});

// create the controller and inject Angular's $scope
scotchApp.controller('searchController', function($scope) {

$location.path(hash); 

});

I want to call a function (perform a search when i click too)

Thanks

Oam Psy
  • 8,555
  • 32
  • 93
  • 157
  • What did you try so far? First thing would be to actually implement your `goToNext()` method in your controller. – muenchdo Feb 20 '14 at 14:11
  • possible duplicate of [Is there a simple way to use button to navigate page as a link does in angularjs](http://stackoverflow.com/questions/15847726/is-there-a-simple-way-to-use-button-to-navigate-page-as-a-link-does-in-angularjs) – Per Hornshøj-Schierbeck Mar 25 '14 at 12:42

1 Answers1

0

as pointed out in the comments, it seems you are missing a goToNext() method, you would implement it like :

scotchApp.controller('mainController',[
   '$scope', '$location', 
   function($scope, $location) {

       $scope.GoToNext2 = function(hash) {
           $location.path(hash);
       };
    }
]);

Next to that, it is nice to have a fallback for routes.. a default: $routeProvider.otherwise({redirectTo : '/'}) which is triggered if the user navigates to a non-existing page.

Hope this helps

BramSlob
  • 11
  • 1