我是AngularJS的新手,我将页面移动到另一页面时遇到问题,我必须将参数从主页传递到详细信息页面,我遵循下面的代码,但无法正常工作,并且出现错误{{1} }
有人可以帮我吗
ReferenceError: $location is not defined at a.$scope.moveToOthers (showOrders.js:4)
var sampleApp = angular.module('sampleApp', ["ngRoute"]);
sampleApp.config(['$routeProvider',
function ($routeProvider) {
$routeProvider.
when('/AddNewOrder', {
templateUrl: 'templates/add_orders.html',
controller: 'AddOrderController'
}).
when('/ShowOrders', {
templateUrl: 'templates/show_orders.html',
controller: 'ShowOrdersController'
}).
when('/ExpandOrders', {
templateUrl: 'templates/expand_orders.html',
controller: 'ExpandOrderController'
}).
when('/OthersPage:id?', {
templateUrl: 'templates/others_page.html',
controller: 'OthersPageController'
}).
otherwise({
redirectTo: '/AddNewOrder'
});
}]);
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script src="controllers/othersPage.js"></script>
<title>AngularJS Routing example</title>
</head>
<body>
<h1>Show orders</h1>
<button ng-click="moveToOthers()" type="button" class="btn btn-default" style="margin:10px 0px 10px 0px;">Others Page</button>
</body>
</html>
答案 0 :(得分:0)
我建议这样做:
'/OthersPage:id?'
更改为'/OthersPage/:id'
<button>
元素上,请勿使用函数来更改您的路径。改为使用ng-href
,例如:<a ng-href="/OthersPage/100" type="button" class="btn btn-default" style="margin:10px 0px 10px 0px;">Others Page</a>