Angular UI-路由器根据传递的值使用模板

Angular UI-Router use template based on passed value

我的 Angular 1.3 应用程序中有一个状态:

    .state('department.filetransfer', {
    url: '/filetransfer/:deptID',
    templateUrl: function($stateParams, $log) {
        return 'modules/department/templates/department.filetransfer.'+$stateParams.deptID+'.html';
    },
    controller: 'DeptFiletransferCtrl as ftc',
    data: {
        pageTitle: 'filetransfer',
        access: 'public'
    }
});

然后在我的应用程序中我有一个 link 例如

ui-sref="department.filetransfer.accounting"

但我收到控制台错误

Error: Could not resolve 'department.filetransfer.accounting' from state 'department'

我错过了什么?

a working example

如何传递 param 的方式是通过 object {paramName1:value1, paramName2: value2}:

ui-sref="department.filetransfer({deptID:accounting})"

上面的例子适用于accounting作为$scope中的变量。

如果我们需要传递字符串值,我们应该这样做:

ui-sref="department.filetransfer({deptID:'accounting'})"

如此处所述

ui-sref

A directive that binds a link (<a> tag) to a state. If the state has an associated URL, the directive will automatically generate & update the href attribute via the $state.href() method. Clicking the link will trigger a state transition with optional parameters.

Also middle-clicking, right-clicking, and ctrl-clicking on the link will be handled natively by the browser.

You can also use relative state paths within ui-sref, just like the relative paths passed to $state.go(). You just need to be aware that the path is relative to the state that the link lives in, in other words the state that loaded the template containing the link.

You can specify options to pass to $state.go() using the ui-sref-opts attribute. Options are restricted to location, inherit, and reload.