简体   繁体   中英

Angular JS Routing with ng-click

I have problem with angular js that I am not able to solve, so I need your help... This is my code:

angular.module("test2", ["ng.route"])

.config(function($routeProvider){

$routeProvider.when ("/contratti",
{
templateUrl:"eleconContrattiAngular.jsp",
controller: "goCTRL"
}

);
});

<a href="#/contratti/rowId=rowId=123">dettaglio</a> `

This will be my configuration with a link... How can i transform this link in a button? I tried with this:

function goCTRL($scope,$location) {
    $scope.goBack = function (hash) {
            $location.path(hash); 
    }       
    }    
 <button ng-click="goBack('#/contratti')">BACK</button>

But it didn't even work...

When using $location.path, you don't want to include the hash (#). According to the description for $location , the path will always start with a forward slash, or a forward slash will be added to the start of the path. That means with your example, you are trying to go to www.yoursite.com/#/#/contratti. Since that isn't a valid path, it's not working.

The easy fix for this is to take out the hash from the function call and see if it works. So in the button, it would be ng-click="goBack('/contratti')" .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM