加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

AngularJS转到状态而不重新加载并且没有值的参数

发布时间:2020-12-17 18:06:50 所属栏目:安全 来源:网络整理
导读:在我的应用程序中,我有一个指令,它查看$location.search()以决定是否应该显示该指令. 代码看起来有点像这样: function refresh(stateName) { var hideSplash = $location.search().nosplash; if (hideSplash === true) { model.hide = true; } else { var t
在我的应用程序中,我有一个指令,它查看$location.search()以决定是否应该显示该指令.
代码看起来有点像这样:

function refresh(stateName) {
    var hideSplash = $location.search().nosplash;

    if (hideSplash === true) {
        model.hide = true;
    } else {
        var templateUrl = getTemplateUrl(stateName);
        if (templateUrl && viewed.indexOf(templateUrl) === -1) {
            viewed.push(templateUrl);
            model.templateUrl = templateUrl;
            model.hide = false;
            model.finished = false;
        }
    }
};

这就像一个魅力.正如你所知,在这种情况下,如果nosplash有一个值并不重要,它只需要预设.
就我而言,路径如下所示:

/摄像头/结果?NOSPLASH

在那条特定的路线上,我把它定义为:

angular.module('widget.wizard')
    .config(pickRoutes);

function pickRoutes($stateProvider) {

    $stateProvider
        .state('home.category.results',configurePickRoute());

    function configurePickRoute() {
        return {
            url: '/results?expanded',reloadOnSearch: false,views: {
                '': {
                    templateUrl: 'scripts/results/results.html',controller: 'ResultsController',controllerAs: 'controller'
                }
            },resolve: {
                bypass: bypassRegistration
            },data: {
                pageTitle: 'Your PiiiCKs'
            }
        };
    };

    //////////////////////////////////////////////////

    /* @ngInject */
    function bypassRegistration($location,pkRegisterService) {
        if (!pkRegisterService.options.bypass) // Checks to see if has been set elsewhere
            pkRegisterService.options.bypass = $location.search().bypass;
    };
};

如您所见,我希望它扩展一个查询参数.目前,我的控制器有:

self.expanded = $stateParams.expanded;

//////////////////////////////////////////////////

function expand() {
    self.expanded = true;
    $state.go('home.category.results',{ expanded: true });
};

在我看来,我有这个HTML:

<div class="panel-more" ng-if="controller.picks">
    <div class="container">
        <div class="row">
            <div class="col-md-12 text-center">
                <button class="btn btn-success" ng-click="controller.expand()" ng-if="!controller.expanded">See your other matches</button>
            </div>
        </div>
    </div>
</div>

<div class="products" ng-if="controller.expanded">
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <h2>Your other matches</h2>
            </div>
        </div>
    </div>
    <div class="product" pk-product="product" pk-category="controller.category" ng-repeat="product in controller.notPicked"></div>
</div>

如您所见,如果展开的属性为true,则隐藏按钮并显示“其他匹配”.
这确实有效,但网址看起来像这样:

/cameras/results?expanded=true

我希望它看起来像这样:

/cameras/results?expanded

有没有办法可以做到这一点,但仍然有reloadOnSearch:false?

解决方法

请试试这个:

网址配置:

url: '/results/:params?'

获得价值:

var params = JSON.parse($stateParams["params"]);
console.log(params.expanded);

去州:

$state.go('home.category.results',{ expanded: true });

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读