Sto usando angolare per fare un e-commerce, e sto impostando uno scroll infinito alla pagina di elenco dei prodotti. Tutto ha funzionato bene, ma desidero utilizzare l'URL per impostare la pagina, in modo che l'utente possa accedere a una pagina specifica tramite URL. come faccio a impostare una variabile come "pageNumber" nell'URL con angolare? come "www.page.com/page/2/"(I vuole ottenere il numero 2 e passarlo al controller negozio)Passare la variabile attraverso l'URL con js angolare
Ecco il codice che ho adesso
(function() {
var app = angular.module('concurseirosUnidos', ['store-directives', 'ngRoute']);
app.config(function($routeProvider, $locationProvider){
$locationProvider.html5Mode(true);
$routeProvider
.when('/', {templateUrl: 'partials/products-list.html'})
.when("/page/$pageNumber"), {
// probably I'd need to put something here?
})
.otherwise({redirectTo:'/'});;
}
});
app.controller('StoreController', ['$http', '$scope', function($http, $scope){
var store = this;
store.products = [];
$http.get('/app/products/products.json').success(function(data){
store.products = data;
});
if(typeof page === 'undefined'){
var page = 1;
}else{
//if it's defined through the url, page = pageNumberFromURL
}
$scope.myLimit = 3 * page;
$scope.nextPage = function() {
page++; // I want this function to actually update the url and get the variable from there
$scope.myLimit = 3 * page;
};
}]);
})();
Ow, grazie ... –
Se questo ha risolto il tuo problema, puoi contrassegnarlo come risposta accettata. – ryeballar
Sure = D, stavo solo controllando se non avessi più domande ... grazie ancora –