如何通过ui视图(ui路由器)传递数据

How do i pass data through ui-view (UI-Router)?

本文关键字:ui 数据 何通过 视图 路由器      更新时间:2023-09-26

我正在使用多个命名视图来嵌套它们。我想做的是将调用模板的div中的一些数据传递到模板本身。

像这样的

<div ui-view="inputtext" data-value="0"></div>
<div ui-view="inputtext" data-value="1"></div>
<div ui-view="inputtext" data-value="2"></div>

我想要相同的模板,但传递不同的数据给它。

我怎样才能做到这一点?

这就是我的状态

.state('project', {
      url: "/project/:projectId",
      views: {
        'project' : {
            templateUrl: "templates/project.html"
        },
        'group@project' : {
            templateUrl: "templates/group.html"
        },
        'task-1@project' : {
            templateUrl: "templates/task-1.html"
        },
        'inputtext@project' : {
            templateUrl: "templates/modules/inputtext.html"
        }
      }

在"项目"中,我有多个"组"在"组"内我有多个"任务"在"task"中,我想显示多个"inputtext",但每个的值不同

function whatyouwannaget()
{

     var scriptUrl = "url";
     $.ajax({
        url: scriptUrl,
        type: 'get',
        dataType: 'html',
        async: false,
        success: function(data) {
            result = data;
        } 
     });
     return result;

您可以使用ui路由器的stateparams

HTML成为

 <a ui-sref=".detail({id: show.id})">{{show.name}}</a>

你的路线配置是这样的.

   .state('app.subscribers.detail', {
    url: 'detail/:id',
    views: {
        'detail@app.shows': {
            templateUrl: 'templates/partials/show-detail.html',
            controller: 'showCtrl'        
        }
    }
});