美国angularjs $ stateProvider不传递参数 [英] States angularjs $stateProvider not passing arguments

查看:421
本文介绍了美国angularjs $ stateProvider不传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用标准$ routeProvider路由的电流angularjs应用。我打算使用应用程序的$ stateProvider的一部分的向导。

我宣布父状态莫代尔和一个孩子的状态editClient'是这样的:

  $ stateProvider.state('模态',{
        观点:{
            莫代尔:{
                templateUrl:* urlHere *',
                控制器:'* controllerHere
            }
        },
        摘要:真
    });    $ stateProvider.state('Modal.editClient',{
        观点:{
            莫代尔:{
                网址:'/ editClient /:身份证',
                templateUrl:* templateHere *',
                控制器:'* controllerHere *'
            }
        }
    });

在我的控制器我打电话:

  $ state.go('Modal.editClient',{ID:1});

然而,$ stateParams是空的。怎么会呢?

我采用了棱角分明的UI路由器版本0.2.15和1.2.25 angularjs。更新到更高angularjs版本是不可能的时刻。

更新

我也试过:

  $ stateProvider.state('Modal.editClient',{
        观点:{
            莫代尔:{
                params:一个{
                    'ID':0
                },
                templateUrl:* templateUrlHere *',
                控制器:'* controllerHere *'
            }
        }
    });


解决方案

在这里您要定义的状态你是不是传递参数状态,你需要做这样的事情。

  $ stateProvider.state('模态',{
        观点:{
            莫代尔:{
                templateUrl:* urlHere *',
                控制器:'* controllerHere
            }
        },
        摘要:真
    });    $ stateProvider.state('Modal.editClient',{
       params:一个{
                        'ID':0
                },
        观点:{
            莫代尔:{
                网址:'/ editClient /:身份证',
                templateUrl:* templateHere *',
                控制器:'* controllerHere *'
            }
        }
    });

I got a current angularjs application using the standard $routeProvider for routing. I intend to use a part of the application the $stateProvider for a wizard.

I declared a parent state 'Modal' and a child state 'editClient' like this:

    $stateProvider.state('Modal', {
        views: {
            'modal': {
                templateUrl: '*urlHere*',
                controller: '*controllerHere'
            }
        },
        abstract: true
    });

    $stateProvider.state('Modal.editClient', {
        views: {
            "modal": {
                url: '/editClient/:id',
                templateUrl: '*templateHere*',
                controller: '*controllerHere*'
            }
        }
    });

In my controller I call:

$state.go('Modal.editClient', { id: 1});

Yet $stateParams is empty. How come?

I'm using angular-ui-router version 0.2.15 and angularjs 1.2.25. Updating to a higher angularjs version is not possible at the moment.

Update

I also tried:

    $stateProvider.state('Modal.editClient', {
        views: {
            "modal": {
                params: {
                    'id' : 0
                },
                templateUrl: '*templateUrlHere*',
                controller: '*controllerHere*'
            }
        }
    });

解决方案

You are not passing argument in state where you are defining your states you need to do something like this.

 $stateProvider.state('Modal', {
        views: {
            'modal': {
                templateUrl: '*urlHere*',
                controller: '*controllerHere'
            }
        },
        abstract: true
    });

    $stateProvider.state('Modal.editClient', {
       params: {
                        'id': 0
                },
        views: {
            "modal": {
                url: '/editClient/:id',
                templateUrl: '*templateHere*',
                controller: '*controllerHere*'
            }
        }
    });

这篇关于美国angularjs $ stateProvider不传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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