Jak zachować model dla różnych tras. na przykład mam listę profili załadowanych na stronę główną. Strona główna zawiera również akcję "ładuj więcej", aby załadować więcej profili, zasadniczo przesyłając dane do modelu. Po kliknięciu określonego profilu widok szczegółów dla tego profilu jest aktywowany przez trasy. Widok szczegółów zawiera przycisk Wstecz, który przekierowuje użytkownika z powrotem na stronę główną. Po przekierowaniu do strony głównej dane (profile) ładowane przez akcję "wczytaj więcej" zostaną utracone. Muszę utrzymać model z „obciążeniem więcej” poprzedzany daneAngularjs zachowuje zmienną zasięgu na różnych trasach
Poniżej znajduje się kod stosowany
/* Controllers */
var profileControllers = angular.module('profileControllers', ['profileServices'])
profileControllers.controller('profileListCtrl', ['$scope','$location', 'Profile','$http',
function($scope,$location, Profile,$http) {
$scope.Profiles = Profile.query(function(){
if($scope.Profiles.length < 3) {
$('#load_more_main_page').hide();
}
});
$scope.orderProp = 'popular';
$scope.response=[];
//LOADMORE
$scope.loadmore=function()
{
$http.get('profiles/profiles.php?profile_index='+$('#item-list .sub-item').length).success(function(response){
if(response) {
var reponseLength = response.length;
if(reponseLength > 1) {
$.each(response,function(index,item) {
$scope.Profiles.push({
UID: response[index].UID,
id: response[index].id,
popular: response[index].popular,
imageUrl: response[index].imageUrl,
name: response[index].name,
tags: response[index].tags,
category: response[index].category
});
});
}
if(reponseLength < 3) {
$('#load_more_main_page').hide();
}
}
});
}
}]);
/* App Module */
var profileApp = angular.module('profileApp', [
'ngRoute',
'profileControllers',
'profileServices',
]);
profileApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/profiles', {
templateUrl: 'partials/profile-list.html',
controller: 'profileListCtrl',
resolve: {
deps: function ($q, $rootScope) {
var deferred = $q.defer();
var dependencies = ['js/sort.js'];
$script(dependencies, function() {
$rootScope.$apply(function() {
deferred.resolve();
});
});
return deferred.promise;
}
}
}).
when('/profiles/:profileId', {
templateUrl: 'partials/profile-detail.html',
controller: 'profileDetailCtrl',
}).
when('/profiles/cat/:category', {
templateUrl: 'partials/profile-list-category.html',
controller: 'profileCategoryListCtrl',
}).
when('/create/', {
templateUrl: 'partials/profile-create.html',
controller: 'profileCreateCtrl',
css: ['css/createprofile.css','css/jquery-ui-1.10.4.custom.min.css','css/spectrum.css'],
}).
otherwise({
redirectTo: '/profiles'
});
}]);
Brzmi jak trzeba UI-router, które utrzymują stan widok. https://github.com/angular-ui/ui-router –
@MikeRobinson Dodałem kod używany w aplikacji do mojego pytania, czy mógłbyś wskazać, w jaki sposób mogę zachować model widoku listy z przedrostkiem danych z obciążenia więcej wezwań do działania w sprawie przekierowania z widoku szczegółowego do widoku listy? –