【问题标题】:How do i pass data through ui-view (UI-Router)?如何通过 ui-view (UI-Router) 传递数据?
【发布时间】:2016-12-12 01:21:54
【问题描述】:

我正在使用多个命名视图来嵌套它们。 我想要做的是将一些数据从调用模板的 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"
        }
      }

在“项目”内,我有多个“组” 在“组”内我有多个“任务” 在“任务”中,我想显示多个“输入文本”,但每个都有不同的值

【问题讨论】:

  • 你可以使用ui路由器参数,或者我个人最喜欢的,使用工厂

标签: javascript jquery angularjs angular-ui-router


【解决方案1】:
function whatyouwannaget()
{


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

【讨论】:

    【解决方案2】:

    你可以使用 ui-router 的 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'        
            }
        }
    
    });
    

    【讨论】:

      猜你喜欢
      • 2019-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-22
      • 1970-01-01
      • 2020-01-15
      • 2015-02-22
      • 1970-01-01
      相关资源
      最近更新 更多