与角UI的路由器preserve状态 [英] Preserve state with Angular UI-Router

查看:81
本文介绍了与角UI的路由器preserve状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NG-观点,即电子邮件发送给从联系人列表中选定的联系人的应用程序。
当用户选择收件人,它显示了另一种观点/页,在那里他可以搜索,过滤器等发送电子邮件和联系人列表是被在NG-视图加载不同的HTML谐音。

I have an app with a ng-view that sends emails to contact selected from a contact list. When the users select "Recipient" it shows another view/page where he can search, filter, etc. "Send email" and "Contact list" are different html partials that are loaded in the ng-view.

我需要保持的发送形式的国家,所以当用户从联系人列表返回到同一点(和相同的状态)的人。我读(使用NG-秀,... $ rootScope,隐藏层)约不同的解决方案,但我想知道,如果UI路由器将帮助我与它的状态管理。如果没有,是否有其他准备使用的解决方案?

I need to keep the send form state so when the users select someone from the Contact List it returns to the same point (and same state). I read about different solutions ($rootScope, hidden divs using ng-show, ...) but I want to know if UI-router will help me with it's State Manager. If not, are there other ready-to-use solutions?

谢谢!

推荐答案

解决方案我已经与正在使用的服务作为我的数据/模型存储。他们坚持在整个控制器的变化。

The solution i have gone with is using services as my data/model storage. they persist across controller changes.

例如

(跨控制器的变化仍然存在我们的模型)上的用户服务

the user service ( our model that persists across controller changes )

app.factory('userModel', [function () {
    return {
        model: {
            name: '',
            email: ''
        }
    };
}]);

在控制器中使用它

using it in a controller

function userCtrl($scope, userModel) {
    $scope.user = userModel;
}

这样做的另一个好处是,你可以像伊斯利重用其他控制器模型。

the other advantage of this is that you can reuse your model in other controllers just as easly.

这篇关于与角UI的路由器preserve状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆