angularjs状态参数不工作

angularjs状态参数不工作,angularjs,Angularjs,尝试使用stage.go()将参数对象传递到状态时遇到问题 以下是我的州定义: .state('drillhole.ddhinttype', { url: '/ddhinttype', templateUrl: VIRTUAL_DIR_PATH + '/App/Views/drillholemanager/drillhole/tabddhinttype.html?v=' + fileVer, controller: 'DrillHoleDdhInt

尝试使用stage.go()将参数对象传递到状态时遇到问题

以下是我的州定义:

.state('drillhole.ddhinttype', {
        url: '/ddhinttype',
        templateUrl: VIRTUAL_DIR_PATH + '/App/Views/drillholemanager/drillhole/tabddhinttype.html?v=' + fileVer,
        controller: 'DrillHoleDdhIntTypeController',
        params: { name: null, description: null }
    })
这是我的控制器:

try {
    angular.module('centric.drillhole.manager');
} catch (e) {
    angular.module('centric.drillhole.manager', ['app.config', 'ui.router', 'kendo.directives', 'ui.bootstrap', 'ngCookies', 'centric.common', 'centric.notification', 'pascalprecht.translate', 'centric.security', 'centric.app.settings']);
}

angular.module('centric.drillhole.manager').controller('DrillHoleDdhIntTypeController', ['$scope', 'CentricUIHelper', 'NumberHelper', 'DrillHoleManagerService', 'app.config', '$stateParams',
function ($scope, uihelper, numberHelper, service, appconfig, $stateParams) {

    $scope.loading = false;

    $scope.isbusy = function () {
        return $scope.loading || $scope.$parent.loading;
    }

    var load = function () {
        var hello = $stateParams.name;
        var hello2 = $stateParams.description;

    };

    load();

}]);
我这样称呼国家:

$state.go('drillhole.ddhinttype', { name: tab.params.name, description: tab.params.description });
在我的控制器中,名称和描述属性始终为空


不知道我错过了什么。有什么想法吗?

在州定义中试试这个:

.state('drillhole.ddhinttype', {
        url: '/ddhinttype',
        templateUrl: VIRTUAL_DIR_PATH + '/App/Views/drillholemanager/drillhole/tabddhinttype.html?v=' + fileVer,
        controller: 'DrillHoleDdhIntTypeController',
        params: { name: null, description: null }
    })
params:{name:undefined,description:undefined}

或者这个:


params:['name','description']

如果您将这些参数放在url中,您将能够在控制器中使用
$stateparms

.state('drillhole.ddhinttype', {
        url: '/ddhinttype/:name/:description',
        templateUrl: VIRTUAL_DIR_PATH + '/App/Views/drillholemanager/drillhole/tabddhinttype.html?v=' + fileVer,
        controller: 'DrillHoleDdhIntTypeController',
        params: { name: null, description: null }
    })

你可以在这里阅读更多关于url路由的信息:

我觉得我应该发布最终结果。我已经决定在URL中传递参数,这样我就可以对多个选项卡重复使用相同的控制器,每个选项卡都具有相同的功能,但针对数据库中的不同表

下面是my base controller中创建选项卡的部分(CoreLogController.js):

现在,我可以访问控制器(drillholedthinttypecontroller.js)每个实例上的ddhinttype变量,该变量告诉它要对哪个表执行操作


由于ddhinttype也包含在URL中,因此用户可以创建一个书签,即使它们是动态生成的,也会直接返回到同一个选项卡。

您是否通过调试器验证了
tab.params.name
tab.params.description
不为空?是的,我检查过了。这些值都在那里,看起来就是这样。现在我只需要弄清楚如何在动态生成的选项卡上设置UISREF属性。
        <tabset>
            <tab ng-repeat="t in statictabs" heading="{{t.heading}}" ui-sref="{{t.route}}" active="t.active"></tab>
            <tab ng-repeat="t in dynamictabs" heading="{{t.heading}}" ui-sref="drillhole.ddhinttype({ddhinttype: '{{t.params.ddhinttype}}'})" active="t.active"></tab>
        </tabset>
    .state('drillhole.ddhinttype', {
        url: '/ddhinttype/{ddhinttype}',
        templateUrl: VIRTUAL_DIR_PATH + '/App/Views/drillholemanager/drillhole/tabddhinttype.html?v=' + fileVer,
        controller: 'DrillHoleDdhIntTypeController',
        params: { ddhinttype: null }
    })