How can I pass data through ui-view (ui-router)?

1

I'm using the nested and named views of ui-router.

What I want to achieve is to be able to pass a data from the div that invokes a template to the template itself.

Something like this:

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

Use the same template in all cases but passing a different value to each one.

That's what the states would be like:

.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"
        }
      }

Within 'project' there are several 'group', within 'group' there are several 'tasks' and within task it is that I want to show several inputtext but with different values.

    
asked by Diego De Dieu 05.08.2016 в 17:45
source

1 answer

1

This code is part of a project I did and an example to guide you.

First you must define a parameter that will receive the view by GET

function myApp($stateProvider) {
    $stateProvider.state('category', {
        url: '/category/:categoryId',
        templateUrl: './frontend/app/search/category/category.html',
        controller: 'category',
        controllerAs: 'vm'
    });
}

In this case it is categoryId . Then make a function in the view controller where you will send the data to go to the view and send the data.

$scope.redictCategory = (select) => {
    $state.go("category", {
        categoryId: select
     });
}

If you notice it, I move between the views by the method .go of the service $state and there I pass the data as a JSON object, which receives the view as a parameter, as I explained in the previous code.

    
answered by 31.05.2017 в 16:44