0

In Aps.net Mvc views called _LoginPartial.cshtml I've added Angular Controller:

    <div class="navbar-right" data-ng-app="PublicApp" data-ng-controller="PublicNotificationsCtrl">
  </div>

And that Login partial is rendered on my default layout using:

@Html.Partial("_LoginPartial")

And below it I have

 @RenderBody()

Which renders body which allays has it's Angular controller.

So in html all this looks like:

            <div class="navbar-right ng-scope" data-ng-controller="PublicNotificationsCtrl" data-ng-app="PublicApp">
                <ul class="nav navbar-nav">
                    <li class="dropdown user-profile-dropdown notifications-dropdown"></li>
                </ul>
                <ul class="nav navbar-nav">
                    <li class="dropdown user-profile-dropdown"></li>
                </ul>
            </div>
        </div>
        <!--

        /.nav-collapse 

        -->
    </div>
<div class="">
    <div  data-ng-controller="PublicRoutinesCtrl" data-ng-app="PublicApp">
        <div class="container" data-ng-show="isMainScreen"></div>
        <div class="container special-container" data-ng-hide="isMainScreen"></div>
    </div>
</div>

But my other controllers don't work anymore as if angular is not loaded (for example I see {{test.Value}} instead of real value)

In console I don't get any errors. Why is this happening ?

EDIT

I've put blank div in my main layout page like this:

<div data-ng-app="PublicApp" data-ng-controller="PublicNotificationsCtrl">

                </div>

But with same result

2
  • Are your other controllers still inside of your root ng-app div? Commented Apr 11, 2014 at 17:50
  • I don't have root ng-app every time I call controller I do it this way: <div data-ng-app="PublicApp" data-ng-controller="PublicNotificationsCtrl"> Commented Apr 11, 2014 at 17:52

1 Answer 1

3

Based on your comment that you instantiate your ng-app with each div, that sounds to be the problem. You can only have one ng-app per page, which is typically the body or html element in the page.

From the angular docs:

Only one AngularJS application can be auto-bootstrapped per HTML document. The first ngApp found in the document will be used to define the root element to auto-bootstrap as an application. To run multiple applications in an HTML document you must manually bootstrap them using angular.bootstrap instead. AngularJS applications cannot be nested within each other. -- http://docs.angularjs.org/api/ng.directive:ngApp

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.