简体   繁体   English

用ng-click进行Angular JS路由

[英]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 js问题,因此需要您的帮助...这是我的代码:

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 (#). 使用$ location.path时,您不想包含哈希(#)。 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. 根据$ location的描述,该路径将始终以正斜杠开头,或者将正斜杠添加到该路径的开头。 That means with your example, you are trying to go to www.yoursite.com/#/#/contratti. 这意味着在您的示例中,您尝试访问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')" . 因此,在按钮中,将为ng-click =“ goBack('/ contratti')”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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