Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 角度ui路由器参数,如果特定的子url_Angularjs_Angular Ui Router - Fatal编程技术网

Angularjs 角度ui路由器参数,如果特定的子url

Angularjs 角度ui路由器参数,如果特定的子url,angularjs,angular-ui-router,Angularjs,Angular Ui Router,是否有一种方法可以在命中特定状态时定义$stateParams值。 我有一个父状态,其中有两个子状态都使用相同的视图: .state('customer { url: '/customer', templateUrl: '/customer/overview/customer.overview.html', resolve: customerResolve, controller: 'customer.overview.controller', param

是否有一种方法可以在命中特定状态时定义$stateParams值。 我有一个父状态,其中有两个子状态都使用相同的视图:

.state('customer {
    url: '/customer',
    templateUrl: '/customer/overview/customer.overview.html',
    resolve: customerResolve,
    controller: 'customer.overview.controller',
    params: { type: null }
})

.state('customer.a' {
    url: '/a',
    templateUrl: '/customer/overview/customer.overview.html',
    resolve: customerResolve,
    controller: 'customer.overview.controller',
    params: { type: 'a' }
})

.state('customer.b' {
    url: '/b',
    templateUrl: '/customer/overview/customer.overview.html',
    resolve: customerResolve,
    controller: 'customer.overview.controller',
    params: { type: 'b'}
})
他们都有同样的决心:

var customerResolve = {

    resolvedCustomers: ['$state', '$stateParams', function ($state, $stateParams) {

        if ($stateParams.type == "a")
        {
            //resolve data
        }
        else if ($stateParams.status == "b") {

            //resolve data
        }
    }]
}
当我导航到../customer/a时,我确实达到了我的解决方案,但我希望
$stateParams.type
a
,但它是
null
../customer/b也一样

该值为
null
,因为父状态是这样定义的。我无法删除父参数,因为这将在解析中完全删除我的类型参数。我只想在父状态中定义类型参数,但不应用“null”或其他值,我希望子状态填充该类型参数

我可以使用ui sref实现它,如下所示:
客户类型A


但是我想通过导航到url来设置类型参数。如果需要更清晰的说明,我可以提供一个plunkr。

就像我最近做的那样

myApp.config( function($routeProvider) {
      when('/user/:userID', {
        templateUrl: 'app/partials/user.html',
        controller: 'userPageCtrl'
      })
  });
然后在你的控制器里

myApp.controller('userPageCtrl', ['$scope','$routeParams',
function($scope, $routeParams) {

    console.log("user controller");
    console.log("route param", $routeParams);
});
$routeParams
将具有用户ID,URL由
/user/2
/user/3
等访问


编辑:我认为这是类似的,即在angular ui中使用
:param
语法,理想情况下,您不必像您的配置那样,在您的父级和所有子级都有相同的
模板
控制器
。但是,如果您确实需要您提到的内容,您可以使用状态配置中可用的
数据
属性,并使用
$state.current.data


我已经创建了一个使用相同的示例来演示您的用例

但不完全是我想要的。我在这个页面上没有id参数,因为它是一个特定类型的多个客户的概述。我对两种类型的客户使用相同的页面和控制器。在您的控制器中,您不能只使用基于参数的and if语句吗?Userid可以很容易地成为usertype参数。我的理解是,您需要
:routeParameter
语法,我认为这是相同的。这确实起到了作用,也是我所需要的。非常感谢。