Preserve state with Angular UI-Router

后端 未结 3 1469
我寻月下人不归
我寻月下人不归 2021-01-31 10:29

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, filte

3条回答
  •  无人及你
    2021-01-31 11:08

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

    example

    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.

提交回复
热议问题