问题:从页面A跳转到页面B,需要将A页面的某个值通过路由传递到页面B。
A页面:
通过v-click()方法,实现跳转。
<div class="funt_bot_item" v-repeat="item in funds" v-click="getFund(item)">
<img src="/static/css/img/funt/cash.svg" />
<span class="funt_bot_item_text">{{item.fund}}</span>
<span id="rightAn">
¥{{item.balance}}
</span>
</div>
A页面的控制器:
在控制器中需要注入$context
服务。
fundCtrl.$inject = ['$scope', '$remote', "$timeout", "$filter", "$context", "$rootScope", "$modal"];
function fundCtrl($scope, $remote, $timeout, $filter, $context, $rootScope, $modal) {
//跳转到B页面,并通过该方法将参数item带过去
$scope.getFund = function(item) {
$scope.$context.setNextScope({
item: item
})
$scope.goto("/B");
}
}
配置路由页面:
$stateProvider
.state('B', {
url: '/B',
templateUrl: 'htmls/B.html'
});
/******路由配置结束******/
//默认装置路由
$urlRouterProvider.otherwise(function ($injector) {
var $state = $injector.get("$state");
$state.go("index");
});
B页面:
可以直接通过双大括号进行值得接收,也可以在B页面的控制器中对传来的值进行操作。
<div class="counts">
<div class="countsItem" v-repeat="item in counts">
<span id="">
{{item.date}}
</span>
<span id="" class="pull-right">
{{item.pay}}
</span>
</div>
</div>
B页面的控制器:
直接可以拿到传来的item的值。
var item = $scope.item;