2

I have a sample HTML like this where each div represent tons of html code. I need to attach a piece of html code to a controller which is already attached to one div. Both the first and last div represent the same business functionality and are tightly coupled and hence I cannot use services to share the state. I am looking for a solution other than using angular or ui routing.

<div ng-controller='newController'>
<label>{{greeting}}</label>
</div>

<div>
<!-- Another Big HTML element -->
</div>

<div>
<!-- This is some popup dialog code which should be attached to the scope of newController -->
<label>{{greeting}}</label>
</div>
1
  • @user3151330 heeey, if my answer work out for you, mark as accepted 8) Commented Mar 18, 2016 at 18:18

1 Answer 1

4

You just have to attach ng-controller to the div's that you want, like this:

<div ng-controller='newController'>
    <label>{{greeting}}</label>
</div>

<div>
    <!-- Another Big HTML element -->
</div>

<div ng-controller='newController'>
    <!-- This is some popup dialog code which should be attached to the scope of newController -->
    <label>{{greeting}}</label>
</div>
Sign up to request clarification or add additional context in comments.

2 Comments

I think it doesn't work. Whenever angular sees an ng-controller it instantiates a new controller object. Please see the plunker below. Click the buttons and you understand what I'm talking about. plnkr.co/edit/o80j1iWaPmrEdGExCK09?p=preview
I think that It is due to the third div in your example is not refreshed by buttons plnkr.co/edit/o80j1iWaPmrEdGExCK09?p=preview. The buttons do the magic...

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.