我有一個URL結構,看起來像這樣:您可以將範圍繼承到子頁面嗎?
when('/:location',{
controller: 'locationController',
templateUrl: 'partials/single.html',
}).
when('/:location/karta',{
redirectTo: '/:location/karta/CYKLING'
}).
when('/:location/karta/:type',{
templateUrl: 'partials/directions.html'
}).
及以下控制器:爲相同
controller('locationController', function($scope, $location, $routeParams, instagram, swimlocations) {
$scope.name = $routeParams.location;
$scope.location = swimlocations.getLocation($routeParams.location)
instagram.getPhotosByLocation($scope.location.long,$scope.location.lat, 100, function(data){
$scope.images = data;
});
}).
controller('directionController'. function($scope, $location, $routeParams, swimlocations) {
$scope.name = $routeParams.location;
$scope.location = swimlocations.getLocation($routeParams.location)
}).
正如你可以看到,兩個控制器都好,除了第一一個向instagram發出請求。有什麼辦法可以避免這種代碼重複?
有什麼例子的名字嗎? – Himmators
其實我的網速度慢...不能夠jsfiddle ....名稱=連線後端....在網站前面 – vijay
不,我不明白.... – Himmators