1

In my AngularJS webapp based on ui-router, I have a state with several views.

I'd like to use the same template/controller (same instance of the controller) in 2 different views with a parameter. I already have the template and the controller.

  .state('home.action', {
    url: '/action',
    views:{
      '[email protected]':{
        templateUrl: 'criteria.html'
      },
    }
  })

I would need to have a string parameter with a static value different for the 2 views.

In action.html:

<div ui-view="criteria"/> //with param="criterias1"
<div ui-view="criteria"/> //with param="criterias2"

I'd like to use this param in the criteria.html template.

What is the best solution for implementing this ?

Regards.

1

2 Answers 2

0
.state('home.action', {
    url: '/action/:theValue',
    templateUrl: 'criteria.html'
  })
.state('home.action', {
    url: '/action/:theValue',
    templateUrl: 'criteria.html'
  })

The values, theValue is available inside your controller as, $stateParams.theValue

Sign up to request clarification or add additional context in comments.

1 Comment

Right but I have only one instance of the controller.
-1

I've found the solution.

Duplicate of this question

It works with onload.

Example: HTML

<script type="text/ng-template" id="section.html">
    <div>section {{ someValue }}. Type : {{ type }}</div>
</script>

<script type="text/ng-template" id="main.html">
    <h2>main content</h2>
    <div ui-view="section1" onload="type = 'type1'"></div>
    <div ui-view="section2" onload="type = 'type2'"></div>
</script>

<div>
    <h1>header</h1>
    <div ui-view></div>
<div>

And same state.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.