AngularJS-如何在路由之间传递数据?

时间:2019-11-01 23:53:44

标签: angularjs angular-routing

我有以下代码:

app.factory(CService.Id,
    ["$rootScope", "$route", "$routeParams", "$location", "$timeout",
        ($rootScope, $route, $routeParams, $location, $timeout) =>
            new CService($rootScope, $route, $routeParams, $location, $timeout)]);

app.config(['$routeProvider', '$locationProvider',
    function ($routeProvider, $locationProvider) {
        $routeProvider.
            when('/', {
                templateUrl: 'page1.html',
                controller: 'page1Controller',
                controllerAs: 'ctl',
                reloadOnSearch: false
            }).
            when('/', {
                templateUrl: 'page2.html',
                controller: 'page2Controller',
                controllerAs: 'ctl',
                reloadOnSearch: false
            }).

在page1.html

<div>
 <input ng-model="ctl.field">
</div>

现在我想将值field从page1.html传递给page2.html,例如,当单击重定向按钮(this.location.path(/page2.html))时,该怎么做?

谢谢

0 个答案:

没有答案