Làm cách nào để duy trì mô hình trên các tuyến đường. ví dụ tôi có một danh sách các hồ sơ được tải lên trang chủ. Trang chủ cũng chứa hành động "tải thêm" để tải thêm cấu hình, về cơ bản đẩy dữ liệu vào mô hình. Khi nhấp vào một cấu hình cụ thể, chế độ xem chi tiết cho cấu hình đó được kích hoạt thông qua các tuyến đường. Chế độ xem chi tiết có nút quay lại để chuyển hướng người dùng quay lại trang chủ. Khi định tuyến lại dữ liệu trang chủ (tiểu sử) được tải bởi hành động "tải thêm" bị mất. Tôi cần phải duy trì các mô hình với "nạp thêm" prepended dữ liệuangularjs duy trì biến phạm vi trên các tuyến đường
Dưới đây là các mã được sử dụng
/* 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'
});
}]);
Âm thanh như bạn cần ui-router, duy trì trạng thái xem. https://github.com/angular-ui/ui-router –
@MikeRobinson Tôi đã thêm mã được sử dụng trong ứng dụng vào câu hỏi của tôi, bạn có thể vui lòng hướng dẫn cách tôi có thể duy trì mô hình xem danh sách với dữ liệu đã được thêm trước từ tải không nhiều lời gọi hành động hơn khi định tuyến lại từ chế độ xem chi tiết đến chế độ xem danh sách? –