Angularjs導航項目我有我的base.html文件:呼叫詳細信息視圖
<div ng-controller=NavCtrl>
<nav>
<a ng-click="getWork(work)" ng-repeat='work in works'>{{$index+1}}</a>
</nav>
</div>
我的路由器:
.config(function($routeProvider) {
$routeProvider
.when('/ardiye/:workNo', {
controller:'DetailCtrl',
templateUrl:'/static/web/js/api/templates/detail.html'
});
})
而且我contrrollers:
.controller('NavCtrl', function($scope, $location, $http) {
$scope.works = [];
$http({method: 'GET', url: '/api/v1/work'}). //collects all works
success(function(data, status, headers, config) {
$scope.works = data.objects;
});
// Trying to pass the selected work to new view, how?
$scope.getWork = function(work) {
$scope.selectedWork=work;
$location.path('/ardiye/'+work.id+'/') };
})
.controller('DetailCtrl', function($scope) {
// here i have to get the selectedWork, how?
})
detail.html:
<h1>{{selectedWork.title}}</h1>
導航控制器發送作品列表。然後當點擊鏈接時,我想通過路由器將工作對象發送到新的細節控制器(爲了不再發起服務器調用)。
但是,當點擊鏈接'getWork'功能不能被調用,我不能將工作對象發送到詳細控制器。我怎樣才能做到這一點?
我cuould不讓它通過增加$ location.path工作... – ratata
你做了什麼?你可以發佈你的代碼和平? –